【Ruby】rbenvでruby1.9.1-p430をインストールしようとしたらハマった
rbenvでrubyのバージョン1.9.1-p430をインストールしようとしたらハマったのでメモ。
環境
現象
rbenv install 1.9.1-p430
を実行したところ、下記のようなエラーログを吐いてインストール出来なかった。
configure: WARNING: unrecognized options: --with-readline-dir checking build system type... i386-apple-darwin14.0.0 checking host system type... i386-apple-darwin14.0.0 checking target system type... i386-apple-darwin14.0.0 checking whether the C compiler works... no configure: error: in `/var/folders/61/8kytz9bj4szbhmj5l7jt3mm40000gn/T/ruby-build.20141230202407.88569/ruby-1.9.1-p430': configure: error: C compiler cannot create executables See `config.log' for more details.
注目したのはerror: C compiler cannnot create executables
の箇所。
どうやらgccがおかしいらしい。きっとこれもclangのせいである。
解決策
homebrewでapple-gcc42をインストールし、
% brew install apple-gcc42
% CC=gcc-4.2 brew install 1.9.1-p430
と実行する
経緯
調べてみたところ、やはり同じようなエラーで困った人が。
http://qiita.com/laiso/items/fe627d77c92b51874931
gccのバージョンが原因のよう。とりあえずhomebrewで昔インストールしたgcc49(証明書周り?が面倒でインストールしただけ。)をアンインストール。
そしてとりあえずまた
rbenv install 1.9.1-p430
を実行してみると次のようなエラーが出力されました。
ERROR: This package must be compiled with GCC, but ruby-build couldn't find a suitable `gcc` executable on your system. Please install GCC and try again. DETAILS: Apple no longer includes the official GCC compiler with Xcode as of version 4.2. Instead, the `gcc` executable is a symlink to `llvm-gcc`, a modified version of GCC which outputs LLVM bytecode. For most programs the `llvm-gcc` compiler works fine. However, versions of Ruby older than 1.9.3-p125 are incompatible with `llvm-gcc`. To build older versions of Ruby you must have the official GCC compiler installed on your system. TO FIX THE PROBLEM: Install Homebrew's apple-gcc42 package with this command: brew tap homebrew/dupes ; brew install apple-gcc42 You will need to install the official GCC compiler to build older versions of Ruby even if you have installed Apple's Command Line Tools for Xcode package. The Command Line Tools for Xcode package only includes `llvm-gcc`. BUILD FAILED
1.9.3-p125より古いrubyをコンパイルするためにはapple-gcc42を使って欲しいとのこと。
そこで
% brew install apple-gcc42
を実行して、apple-gcc42をインストール。
これだけでは
% rbenv install 1.9.1-p430
としてもapple-gcc42を使ってくれない。(clangが使われてしまう)
そのため
% CC=gcc-4.2 brew install 1.9.1-p430
とgccのバージョンを指定して実行してあげることでインストールすることが出来ました!