【Mac】rbenvでRubyがインストールできない時の対応 (OS X Yosemite 10.10.1)

スポンサーリンク

先日重い腰を上げて OS X Yosemite 10.10.1 にバージョンアップしてから特に不具合はなく快適だったのですが、rbenv で Ruby をインストールしようとしたら失敗してしまいました。一応インストールは出来たんですけど、調べても解決策が見つからないし原因もよくわからなかったので、同じような事象の人がいたらログで検索して引っかかるようにのっけておきます。

rbenvでRubyをインストールしようとして失敗

$ rbenv install 2.0.0-p598
Downloading ruby-2.0.0-p598.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/4136bf7d764cbcc1c7da2824ed2826c3550f2b62af673c79ddbf9049b12095fd
Installing ruby-2.0.0-p598...

BUILD FAILED (OS X 10.10.1 using ruby-build 20141128)

Inspect or clean up the working tree at /var/folders/7b/zfmhk6ld50s5g5bb6kp5_cqr0000gn/T/ruby-build.20141201231624.39825
Results logged to /var/folders/7b/zfmhk6ld50s5g5bb6kp5_cqr0000gn/T/ruby-build.20141201231624.39825.log

Last 10 log lines:
make[2]: *** [../../../.ext/x86_64-darwin14.0.0/io/wait.bundle] Error 1
make[1]: *** [ext/io/wait/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** No rule to make target `../.././ext/json/lib/json/add/bigdecimal.rb', needed by `../../.ext/common/json/add/bigdecimal.rb'.  Stop.
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [ext/json/all] Error 2
installing default callback libraries
linking shared-object dl/callback.bundle
ld: warning: directory not found for option '-L/Users/hogeuser/.rbenv/versions/2.0.0-p598/lib'
make: *** [build-ext] Error 2

調べても何も出てこないので、前も同じような現象になった時に ruby-build か readline が原因だったなと思いだしてbrew updateからのbrew upgradeするが何もない。Command Line Tools かもしれないとあたりをつけて、思いつく限りのコマンドを打ってみる。

$ xcodebuild -version
Xcode 6.1
Build version 6A1052d

$ xcode-select -v
xcode-select version 2339.

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

これらのコマンドが打てるという事はインストールはされてるのでバージョンが違うのかもしれないと考えてみる。ただ Command Line Tools 自体のことを正直わかってないので、見てもよくわかりません。とりあえずインストール?アップデート?してみます。

$ xcode-select --install

f:id:tasukujp:20141202010502p:plain

結果、何も変わってない…。いや、正確にはgcc -vで出てきた --with-gxx-include-dir が変わってる。

$ xcodebuild -version
Xcode 6.1
Build version 6A1052d

$ xcode-select -v
xcode-select version 2339.

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

お手上げなので何か変わったかもしれないともう一回インストールにトライしてみる。

$ rbenv install 2.0.0-p598 
Downloading ruby-2.0.0-p598.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/4136bf7d764cbcc1c7da2824ed2826c3550f2b62af673c79ddbf9049b12095fd
Installing ruby-2.0.0-p598...
Installed ruby-2.0.0-p598 to /Users/tasukujp/.rbenv/versions/2.0.0-p598

いけました。結局原因は Command Line Tools だったのでしょうか。

追記

Homebrewのコマンドbrew --configを使うと Command Line Tools のバージョンを確認できました。

$ brew --config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: de0aa4cd534611aca9145a06d41f6e47802b67d9
Last commit: 24 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit haswell
OS X: 10.10.1-x86_64
Xcode: 6.1
CLT: 6.1.0.0.1.1413057044
Clang: 6.0 build 600
X11: N/A
System Ruby: 2.0.0-481
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: /Users/tasukujp/.rbenv/shims/ruby

Apple DeveloperのダウンロードサイトでCommand Line Tools を確認してみると「OS X 10.10 for Xcode 6.1.1」が11月14日リリースになってますね。Xcode 6.1はインストールしたけどCommand Line Tools はしてなかったのでこれで間違いなさそうです。

f:id:tasukujp:20141202222813p:plain

Command Line Tools のダウンロードページ

Apple Developer -> Xcode -> Related Downloads and Resources の Additional Tools