rvmでruby のバージョン管理

環境

OSX Lion ( 10.7.3 )
Xcode 4.3

rvm をインストールします*1

$ git clone https://github.com/wayneeseguin/rvm.git
$ bash rvm/install

インストール後、すぐにはrvmは使えません。
.bashrcや.zshrcにrvmのパスが追加されているので、読み込みます。

$ . ~/.zshrc

インストール可能なrubyのバージョンを確認します。

$ rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p358]
[ruby-]1.8.7-head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2-p318
[ruby-]1.9.2[-p320]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3-p125
[ruby-]1.9.3-[p194]
[ruby-]1.9.3-head
ruby-head
…

最新版のruby 1.9.3 をインストールします。

rvm install 1.9.3

続いて1.8.7をインストールします

$ rvm install 1.8.7
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.

が、エラー

$ rvm requirements
…
Xcode 4.2:
 * is only supported by ruby 1.9.3+
 * it breaks gems with native extensions, especially DB drivers.

Xcode 4.3+ users
- please be warned
- only ruby-1.9.3-p125+ is partially supported
- in case of any compilation issues:
 * downgrade to Xcode 4.1
 * uninstall Xcode and install osx-gcc-installer
and reinstall your rubies.

xcode4.3だと1.9.3しか入れられないみたいです。
rvm内でrubyのバージョン変更したかったんですが、仕方ないのでrvmを有効化するかどうかでバージョン変更することにします。

rvmを無効にします

$ rvm system
$ rvm -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]

rvmで1.9.3を使います

$ rvm 1.9.3
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]

んー。4.3からコンパイラがllvm-gccに移ってきてる影響が大きいですね。まだ4.3を使うのは微妙ですね。

参考
RVM: Ruby Version Manager - './install' - Installing RVM.
RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation

*1:git を使うので、gitを予めインストールしておきます。