Ruby Language 1. Install and manage versions of Ruby with rbenv


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 ~/.rbenv

Then clone the ruby-build plugin:

$ git clone ~/.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 -)"

(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)


[1]: Understanding PATH