The easiest way to install and manage various versions of Ruby with rbenv is to use the ruby-build plugin.
First clone the rbenv repository to your home directory:
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Then clone the ruby-build plugin:
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Ensure that rbenv is initialized in your shell session, by adding this to your .bash_profile
or .zshrc
:
type rbenv > /dev/null
if [ "$?" = "0" ]; then
eval "$(rbenv init -)"
fi
(This essentially first checks if rbenv
is available, and initializes it).
You will probably have to restart your shell session - or simply open a new Terminal window.
Note: If you're running on OSX, you will also need to install the Mac OS Command Line Tools with:
$ xcode-select --install
You can also install rbenv
using Homebrew instead of building from the source:
$ brew update
$ brew install rbenv
Then follow the instructions given by:
$ rbenv init
Install a new version of Ruby:
List the versions available with:
$ rbenv install --list
Choose a version and install it with:
$ rbenv install 2.2.0
Mark the installed version as the global version - i.e. the one that your system uses by default:
$ rbenv global 2.2.0
Check what your global version is with:
$ rbenv global
=> 2.2.0
You can specify a local project version with:
$ rbenv local 2.1.2
=> (Creates a .ruby-version file at the current directory with the specified version)
Footnotes:
[1]: Understanding PATH