homebrewを使って
1. rbenvのインストール
brew install rbenv brew install readline # パスを通して echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile # 設定を追記 echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile # 設定をリロードしておかないとこのあとrbenvで設定したrubyのバージョンに変わらない source ~/.bash_profile brew install ruby-build brew install rbenv-gemset brew install rbenv-gem-rehash
2. rbenvの更新
rm -rf ~/.rbenv/plugins/ruby-build git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
3. 確認してみる
$ rbenv -h rbenv 0.4.0 Usage: rbenv <command> [<args>] Some useful rbenv commands are: commands List all available rbenv commands local Set or show the local application-specific Ruby version global Set or show the global Ruby version shell Set or show the shell-specific Ruby version install Install a Ruby version using ruby-build uninstall Uninstall a specific Ruby version rehash Rehash rbenv shims (run this after installing executables) version Show the current Ruby version and its origin versions List all Ruby versions available to rbenv which Display the full path to an executable whence List all Ruby versions that contain the given executable See `rbenv help <command>' for information on a specific command. For full documentation, see: https://github.com/sstephenson/rbenv#readme
4. 使ってみる
ruby 2.1.2あたりが最新なのでそこら辺にしてみる
$ rbenv install 2.1.2 $ rbenv rehash $ rbenv global 2.1.2 $ ruby -v ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin12.0]
環境ごとのGemを用意する
Gem の環境がシステムで使われているものと一体になってしまっているので gemset を新たに作る
$ rbenv gemset create 2.1.2 rails-sample $ rbenv gemset list 2.1.2: rails-sample $ echo rails-sample > .rbenv-gemsets $ rbenv gemset active rails-sample global # 場所変えると適用されない $ cd $ rbenv gemset active no active gemsets
おわり