こんにちは、Watanabeです。
環境
brewから最新版のRubyが取得できない
$ brew upgrade rbenv ruby-build
Ruby最新版を取得しようとしてもできない状態になったが、rbenvとruby-buildを再インストールしたら解決した。
$ brew uninstall rbenv ruby-build $ brew install rbenv ruby-build
BUILD FAILEDエラー
$ rbenv install 3.3.0 ruby-build: using openssl@3 from homebrew ==> Downloading ruby-3.3.0.tar.gz... -> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 21.0M 100 21.0M 0 0 17.2M 0 0:00:01 0:00:01 --:--:-- 17.5M ==> Installing ruby-3.3.0... ruby-build: using libyaml from homebrew ruby-build: using gmp from homebrew -> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --with-openssl-dir=/usr/local/opt/openssl@3 --enable-shared --with-libyaml-dir=/usr/local/opt/libyaml --with-gmp-dir=/usr/local/opt/gmp --with-ext=openssl,psych,+ -> make -j 8 BUILD FAILED (macOS 14.1.2 on x86_64 using ruby-build 20240119) You can inspect the build directory at /var/folders/2p/jld6b7mn5n74dp5r5ydkx3_40000gn/T/ruby-build.20240220010937.52845.wnLlSZ See the full build log at /var/folders/2p/jld6b7mn5n74dp5r5ydkx3_40000gn/T/ruby-build.20240220010937.52845.log
Rubyのインストールで躓くのが初めてだったのですこし困惑。ログを出してくれているので見に行く。
2 errors generated. make: *** [debug.o] Error 1 make: *** Waiting for unfinished jobs.... In file included from compile.c:40: ./vm_callinfo.h:179:9: error: use of undeclared identifier 'RUBY_FUNCTION_NAME_STRING' rp(ci); ^ ./internal.h:93:72: note: expanded from macro 'rp' #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING) ^ In file included from compile.c:40: ./vm_callinfo.h:221:16: error: use of undeclared identifier 'RUBY_FUNCTION_NAME_STRING' if (debug) rp(ci); ^ ./internal.h:93:72: note: expanded from macro 'rp' #define rp(obj) rb_obj_info_dump_loc((VALUE)(obj), __FILE__, __LINE__, RUBY_FUNCTION_NAME_STRING) ^ 2 errors generated. make: *** [compile.o] Error 1 external command failed with status 2
2箇所でエラーが出ているらしい。
error: use of undeclared identifier 'RUBY_FUNCTION_NAME_STRING'
とrp
あたりがヒントになりそう。
とはいえログとにらめっこしても原因はわからないのでググります。
rbenvとruby-buildのうち、ruby-buildが個別のRubyの管理を担っているのでこちらに原因がありそう。 wikiを確認します。
ruby-buildを使用する際にほかにも必要なライブラリがあるとのことです。このあたりが原因かも?
# install Xcode Command Line Tools xcode-select --install # install dependencies with Homebrew brew install openssl@3 readline libyaml gmp
ここで再度ググってみたところXcode由来のBuild Errorに対応した記事に行き着きました。
Xcode最新版をインストールしてみる。
$ xcode-select --install
再度、Ruby3.3.0のインストールにチャレンジ。
$ rbenv install 3.3.0 ruby-build: using openssl@3 from homebrew ==> Downloading ruby-3.3.0.tar.gz... -> curl -q -fL -o ruby-3.3.0.tar.gz https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.0.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 21.0M 100 21.0M 0 0 25.2M 0 --:--:-- --:--:-- --:--:-- 25.4M ==> Installing ruby-3.3.0... ruby-build: using libyaml from homebrew ruby-build: using gmp from homebrew -> ./configure "--prefix=$HOME/.rbenv/versions/3.3.0" --with-openssl-dir=/usr/local/opt/openssl@3 --enable-shared --with-libyaml-dir=/usr/local/opt/libyaml --with-gmp-dir=/usr/local/opt/gmp --with-ext=openssl,psych,+ -> make -j 8 -> make install ==> Installed ruby-3.3.0 to /Users/nabeyu/.rbenv/versions/3.3.0
成功しました🙌
補足 Xcodeとは
Xcodeは、Appleが開発した統合開発環境(IDE)で、macOSやiOS、iPadOS、watchOS、tvOSなどのアプリケーションやソフトウェアの開発に使用される。
xcode-selectは、コマンドラインツールのインストールと管理を行うためのコマンドラインツール。Xcodeをインストールすると、一部のコマンドラインツールも同時にインストールされるが、場合によっては追加のツールが必要になることがあります。xcode-selectコマンドは、特定のバージョンのXcodeを選択したり、コマンドラインツールをインストールしたりするために使用されます。