inohilog

/var/log/inohiro.log

rvm を使って Ruby を使い分ける

Ruby 1.9.2とかRubiniusとかIronRubyを入れてみようと思ったのですが、そういうときにrvm(Ruby Version Manager)が便利そうなので導入してみました。

rvm の導入


$ uname -a
Linux ubuntu 2.6.32-24-generic #39-Ubuntu SMP Wed Jul 28 06:07:29 UTC 2010 i686 GNU/Linux

$ sudo gem install rvm
gem コマンドでインストールするだけじゃ終わらなくて、gemコマンドでとってきたrvm-installを実行する必要があります。

$ rvm-install
pathが通ってなかったら「/var/lib/gems/1.8/bin」あたりにあるはずです。

$ pwd
/var/lib/gems/1.8/bin
$ ls
rackup rails rake rvm-install
で、rvm-installを実行すると、何かばーっと表示されます。

# 省略
You must now finish the install manually:
1) Place the folowing line at the end of your shell's loading files(.bashrc or .bash_profile for bash and .zshrc for zsh), after all path/variable settings:
-s $HOME/.rvm/scripts/rvm && source $HOME/.rvm/scripts/rvm
Please note that this must only occur once - so, you only need to add it the first time you install rvm.
# 省略
shellの設定ファイル(.bashrcとか.bash_profileとか)にこの1行「 -s $HOME/.rvm/scripts/rvm && source $HOME/.rvm/scripts/rvm」を追加しろということなので、追記。
(追記: 自分は .bash_profile にかいたのですが、一度ログアウトしてしまうと明示的に読み込まないと読み込んでくれないので(なぜ?)、.bashrcに移動しました。ただし.bashrcにかく場合は、書き足すだけでなく、ちょっと変更が発生するようなので注意が必要です)
shellの設定ファイルをもう一度読み込めばrvmコマンドが使えるようになる。

$ source ~/.bash_profile
$ rvm --version
rvm 1.0.2 by Wayne E. Seguin (wayneeseguin@gmail.com) http://rvm.beginrescueend.com/

Ruby 1.9.2 のインストール


$ rvm install 1.9.2
($ rvm install ruby-head とやると、Rubyのtrunkから最新のものをcheckoutしてくるので注意)
最初にエラーが出て、.rvm/log/***/svn.checkout.error.log あたりを見たら(エラーが起きるとlogファイルの場所を教えてくれる)Subversionがインストールされていないとあったので、インストール。
他にもcurl、bison、patchがインストールされていなかったり、pathが通っていなかったりするとエラーが出たりするようです。

Ruby 1.9.2 を使う


$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
$ rvm use 1.9.2

info: Using ruby 1.9.2 p0
$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

おー。1.9.2が使えるようになった。が、インストール済み1.8.7を使う場合はどうするんだろう。rvm listすると、使えるruby実装がリストされるので、それで見たが1.9.2しか出てこない。rvmで使う用に1.8.7を追加インストールするべきか..?

$ rvm list
rvm rubies

=> ruby-1.9.2-p0 [ i386 ]

Ruby 1.8.7 を使うには...?

おっと...。ここでの1.9.2-headはruby-headと同義なのか、それとも1.9.2p0のことなのか...?


* If you wish to install rbx and/or any MRI head (eg. 1.9.2-head) then you must install and use rvm 1.8.7 first.
とりあえず、rvm install 1.8.7やってみよう。 => 無事インストールできた。

$ rvm list

rvm rubies

ruby-1.8.7-p302 [ i386 ]
ruby-1.9.2-p0 [ i386 ]

そのほかの ruby 実装

そのほかのruby実装(Rubinius, JRuby, IronRuby,REE(Ruby Enterprise Edition))を使うときは、以下のものが必要だよと教えてくれた。

*  For JRuby (if you wish to use it) you will need:
  $ aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk

*  For MRI & ree (if you wish to use it) you will need (depending on what you are installing):
  $ aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf

*  For IronRuby (if you wish to use it) you will need:
  $ aptitude install curl mono-2.0-devel