setoya-blog

システム開発技術、データ分析関連でお勉強したことや、山奥生活を綴る、テンション低めなブログです。

rvmでruby 1.9.3-p362をインストールする

herokuのrubyの1.9.3のパッチレベルがp362に上がるのでローカルの環境も揃えようとしたら例によってハマったので、メモ。⇒あとで分かったが、herokuのパッチレベルはp392だった。。。やり直し。

最初にこれを実行するとエラーが出た。

$ rvm install ruby-1.9.3-p362 --with-openssl-dir=$rvm_path/usr
Installing Ruby from source to: /Users/masato1/.rvm/rubies/ruby-1.9.3-p362, this may take a while depending on your cpu(s)...
ruby-1.9.3-p362 - #downloading ruby-1.9.3-p362, this may take a while depending on your connection...
ruby-1.9.3-p362 - #extracted to /Users/masato1/.rvm/src/ruby-1.9.3-p362 (already extracted)
ruby-1.9.3-p362 - #configuring
ruby-1.9.3-p362 - #compiling
Error running 'make', please read /Users/masato1/.rvm/log/ruby-1.9.3-p362/make.log
There has been an error while running make. Halting the installation.

ログを見てみるとコンパイラでclangが使われているのがダメらしい。確かに、rvm requirementsコマンドで確かめてみると、

$ rvm requirements

Xcode and gcc:

Right now Ruby requires gcc to compile, but Xcode 4.2 and later no longer ship with gcc. Instead they ship with llvm-gcc (to which gcc is a symlink) and clang, neither of which are supported for building Ruby. Xcode 4.1 was the last version to ship gcc, which was /usr/bin/gcc-4.2.

とか言われる。しかもXcodeを最新版にしているので、gcc-4.2は手元にない。
rvm requirements によると、

For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'

と書いていて、かつ、

Xcode 4.2 and later (including Command Line Tools for Xcode):
- If you have gcc-4.2 (and friends) from an earlier Xcode version, Ruby will build fine.
- If you don't have gcc-4.2, you have two options to get it:
 * Install apple-gcc42 from Homebrew
 * Install osx-gcc-installer

  Homebrew:

  If you are using Homebrew, you can install the apple-gcc42 and required libraries from homebrew/dupes:

      brew update
      brew tap homebrew/dupes
      brew install autoconf automake apple-gcc42
      rvm pkg install openssl

  Xcode 4.2+ install or/and Command Line Tools for Xcode is required to provide make and other tools.

と書いているので、実はMacPortを並行して使っているのでhomebrewはあまり使いたくないのだけど、言われたままにやってみる。

$ brew update
$ brew tap homebrew/dupes
$ brew install libksba
$ brew install autoconf automake apple-gcc42

opensslのパッケージは前にいれたのがあるのでいれないで置いた。

その後、homebrewでインストールしたgcc-4.2が使えるようになっているので、

$ CC=gcc-4.2 rvm install ruby-1.9.3-p362 --with-openssl-dir=$rvm_path/usr

とする。