Ruby Version Manager (RVM) is a way to mange multiple version of ruby on the same computer. It is somehow similar to python’s virtualenvs, but has more features, like:

  • list, download and install desired ruby version
  • automatically switch to proper version when one enters a project’s directory
  • etc.

Installation

Is quite easy: see https://rvm.io/.

For Mac additionally we have to install gnupg by calling:

brew install gnupg

(then use gpg insted of gpg2) and for Ubuntu:

sudo apt install gnupg2

Then add the following lines to .zshrc (or .bash_profile or .bashrc):

export PATH="$PATH:$HOME/.rvm/bin"
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

Usage

rvm get head && rvm reload
rvm list known

If you get, Warning! PATH is not properly set up, … you can try to run:

rvm reset

In order to install a MRI version (Matz’s Ruby Interpreter, the original version used by most people) you can type, for example,

rvm install ruby-2.5.1

or simply

rvm install 2.5

In order to use it, type:

rvm use 2.5

If you want to come back to the system version type:

rvm system

ruby-version

One can make use rvm to automatically switch between ruby version. Let’s say we have created a project called bartek-blog.

mkdir bartek-blog

Then we have to enter the directory of the project.

cd bartek-blog

And run the following lines:

rvm  ruby-2.6.1 do rvm gemset create bartek_blog
rvm --ruby-version use  ruby-2.6.1@bartek_blog

This will create files .ruby-gemset and .ruby-version. Now each time ones enter the directory rvm with switch to the desired version of ruby automatically.

Updated: 2020-12-10