☆ MavericksでRuby1.9.3環境設定 - 別館 子子子子子子(ねこのここねこ)もご覧ください。
Mac OS X Lion に複数のRuby を入れる;homebrew、rbenv + ruby-build を使って - noanoa 日々の日記
に従って行う。
mini:~ admin$ brew install rbenv ==> Downloading https://github.com/sstephenson/rbenv/tarball/v0.3.0 ######################################################################## 100.0% ==> Caveats To enable shims and autocompletion, add rbenv init to your profile: if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi ==> Summary /usr/local/Cellar/rbenv/0.3.0: 32 files, 160K, built in 7 seconds mini:~ admin$ brew install ruby-build ==> Downloading https://github.com/sstephenson/ruby-build/tarball/v20120524 ######################################################################## 100.0% ==> ./install.sh /usr/local/Cellar/ruby-build/20120524: 45 files, 196K, built in 2 seconds
.bash_profileに追記。
mini:~ admin$ echo 'eval "$(rbenv init -)"' >> .bash_profile mini:~ admin$ echo 'source ~/.rbenv/completions/rbenv.bash' >> .bash_profile
ターミナル再起動。
-bash: /Users/admin/.rbenv/completions/rbenv.bash: No such file or directory
とエラーが出るので、
https://github.com/sstephenson/rbenv/blob/master/completions/rbenv.bash
から持ってくる。今日時点のrbenv.bashは
_rbenv() { COMPREPLY=() local word="${COMP_WORDS[COMP_CWORD]}" if [ "$COMP_CWORD" -eq 1 ]; then COMPREPLY=( $(compgen -W "$(rbenv commands)" -- "$word") ) else local command="${COMP_WORDS[1]}" local completions="$(rbenv completions "$command")" COMPREPLY=( $(compgen -W "$completions" -- "$word") ) fi } complete -F _rbenv rbenv
インストール可能なバージョンを確認。
mini:~ admin$ rbenv install usage: rbenv install VERSION rbenv install /path/to/definition Available versions: 1.8.6-p383 1.8.6-p420 1.8.7-p249 1.8.7-p302 1.8.7-p334 1.8.7-p352 1.8.7-p357 1.8.7-p358 1.9.1-p378 1.9.2-p180 1.9.2-p290 1.9.2-p318 1.9.2-p320 1.9.3-dev 1.9.3-p0 1.9.3-p125 1.9.3-p194 1.9.3-preview1 1.9.3-rc1 2.0.0-dev jruby-1.6.3 jruby-1.6.4 jruby-1.6.5 jruby-1.6.5.1 jruby-1.6.6 jruby-1.6.7 jruby-1.6.7.2 jruby-1.7.0-preview1 maglev-1.0.0 rbx-1.2.4 rbx-2.0.0-dev ree-1.8.6-2009.06 ree-1.8.7-2009.09 ree-1.8.7-2009.10 ree-1.8.7-2010.01 ree-1.8.7-2010.02 ree-1.8.7-2011.03 ree-1.8.7-2011.12 ree-1.8.7-2012.01 ree-1.8.7-2012.02
一番新しいのがどれなのかよく分かりませんが、1.9.3-p194を選んでインストールします。
mini:~ admin$ rbenv install 1.9.3-p194 Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz... Installing yaml-0.1.4... Installed yaml-0.1.4 to /Users/admin/.rbenv/versions/1.9.3-p194 Downloading http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz... Installing ruby-1.9.3-p194... Installed ruby-1.9.3-p194 to /Users/admin/.rbenv/versions/1.9.3-p194
1.9.3-p194を使うようにセット。
mini:~ admin$ rbenv versions 1.9.3-p194 mini:~ admin$ rbenv global 1.9.3-p194 mini:~ admin$ rbenv rehash mini:~ admin$ rbenv version 1.9.3-p194 (set by /Users/admin/.rbenv/version)
動作するrubyのバージョン確認。
mini:~ admin$ ruby -v ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
おまけ:rubyのバージョン切り替えについて
rbenv で複数のrubyをインストールして切り換える