プログラマでありたい

おっさんになっても、プログラマでありつづけたい

RVMを使ってMacで、Ruby 1.8.7と1.9.3を共存

 Mac OSX(Snow Leopard) でのRuby 1.8.7と1.9.3の共存の設定です。開発環境であれば、手軽なRVMを使うと良いと思います。

RVMのインストール

$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

設定の読み込み

$ source ~/.bash_profile

必要なモジュールの確認
|

$ rvm requirements

Notes for Mac OS X 10.6.8, Xcode 4.2.

For MacRuby: Install LLVM first.

For JRuby: Install the JDK. See http://developer.apple.com/java/download/ # Current Java version "1.6.0_26"
For IronRuby: Install Mono >= 2.6
For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'

You can use & download osx-gcc-installer: https://github.com/kennethreitz/osx-gcc-installer

NOTE: Currently, Node.js is having issues building with osx-gcc-installer. The only fix is to install Xcode over osx-gcc-installer.

To use an RVM installed Ruby as default, instead of the system ruby:

rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7

And reopen your terminal windows.

Xcode 4.2:
* is only supported by ruby 1.9.3+ using command line flag: --with-gcc=clang
* it breaks gems with native extensions, especially DB drivers.

Required Xcode Version 3.2.1 (1613) or later, such as 3.2.6 or Xcode 4.1.

You should download the Xcode tools from developer.apple.com, since the Snow Leopard dvd install contained bugs.

Xcode 4.2 users - please be warned -
in case of any compilation issues
* downgrade to Xcode 4.1
* or install osx-gcc-installer
and reinstall your rubies.

足りないモジュールがあったら、インストールしておきます。

RVM上にrubyのインストール

$ rvm install 1.9.3


MacPortでOpenSSLを入れている場合は、http.rbでSegmentation faultを起こす場合があります。その際は、下記の手順でどうぞ。

rvm pkg install iconv
rvm pkg install openssl
rvm install ruby-1.9.3 --with-openssl-dir=~$rvm_path/usr --with-iconv-dir=$rvm_path/usr 

インストール済みのrubyの一覧

$ rvm list

rvm rubies

=> ruby-1.9.3-p0 [ x86_64 ]

# Default ruby not set. Try 'rvm alias create default <ruby>'.

# => - current
# =* - current && default
#  * - default

切り替え色々

バージョン指定で使用

$ rvm use 1.9.3

デフォルトの設定

$ rvm --default use 1.9.3

デフォルトのversionを使用する

$ rvm default

システム設定のrubyに戻す

$ rvm system

gemのインストール

rootではなく、rvm使用中のユーザ権限で実行してください。

$gem install rails


非常に簡単です。 enjoy!!

RVM: Ruby Version Manager - Installing RVM