Installation

Install rbenv and ruby-build

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Add to ~/.bash_profile

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Verify installation

type rbenv   # → "rbenv is a function"

These are generic instructions; there may be rbenv packages available for your OS.

See: Installation

Managing versions

Command Description
rbenv install -l List all available versions
rbenv install 2.2.1 Install Ruby 2.2.1
rbenv uninstall 2.2.1 Uninstall Ruby 2.2.1
rbenv versions See installed versions
rbenv version See current version
rbenv which <NAME> Display path to executable
rbenv rehash Re-write binstubs

Using versions

Locally

rbenv local 2.2.2 Use Ruby 2.2.2 in project
rbenv local --unset Undo above

Application-specific version numbers are stored in .ruby-version.

Globally

rbenv global 2.2.2 Use Ruby 2.2.2 globally
rbenv global --unset Undo above

Global version numbers are stored in ~/.rbenv/version.

Shell

rbenv shell 2.2.2 Use Ruby 2.2.2 in shell
rbenv shell --unset Undo above

Shell-local version numbers are stored as environment variables.

References