[Ruby on Rails (RoR)] Install Ruby Version Manager (RVM) and try out ruby

Ruby Version Manager (RVM)

RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation - https://rvm.io/

Installation explained

There are three different ways to install and configure RVM.

  • Single-User installations (recommended) - For an isolated install within a user’s $HOME, not for root.

  • Multi-User installations - For server administrators - For an installation usable by all users on the system - Please note that Single-User supersedes Multi-User. This also used to be called the System-Wide Install. Using this type of installation without knowledge how umask works is a big security risk.

  • Mixed mode installations - For an installation usable by all users on the system - with isolated rubies/gemsets within a user’s $HOME. Installation instructions are exactly the same as for Multi-User installations, the difference is in users environment.

Install RVM

1. Install GPG keys

As a first step install GPG keys used to verify installation package:

1
$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

In case you encounter an issues check security

2. Install RVM stable version

1
$ \curl -sSL https://get.rvm.io | bash -s stable

Single-User Install Location: ~/.rvm/

If the install script is run as a standard, non-root user, RVM will install into the current users’s home directory.

3. Reload shell configuration & test

Close out your current shell or terminal session and open a new one (preferred). You may load RVM with the following command:

1
$ source ~/.rvm/scripts/rvm

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command which should output rvm is a function as shown below.

1
2
type rvm | head -n 1
rvm is a function

NOTE: Before reporting problems check rvm notes as it might contain important information.

Congratulations! You have successfully installed RVM.

Try out your new RVM installation

Below are some examples of how to install and use a Ruby under RVM.

Display a list of all known rubies. NOTE: RVM can install many more Rubies not listed.

1
2
3
4
5
6
7
8
9
10
11
12
rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-p374]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p320]
[ruby-]1.9.3[-p545]
[ruby-]2.0.0-p353
[ruby-]2.0.0[-p451]
[ruby-]2.1[.1]
[ruby-]2.1-head
ruby-head

Install a version of Ruby (eg 2.1.1):

1
2
3
4
5
6
7
8
$ rvm install 2.1
Checking requirements for opensuse.
Requirements installation successful.
Installing Ruby from source to: ~/.rvm/rubies/ruby-2.1.1, this may take a while depending on your cpu(s)...
...
Install of ruby-2.1.1 - #complete
Using ~/.rvm/gems/ruby-2.1.1
Use the newly installed Ruby:
1
2
3
$ rvm use 2.1
Using ~/.rvm/gems/ruby-2.1.1
Check this worked correctly:
1
2
$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
1
2
3
$ which ruby
~/.rvm/rubies/ruby-2.1.1/bin/ruby
Optionally, you can set a version of Ruby to use as the default for new shells. Note that this overrides the 'system' ruby:
1
$ rvm use 2.1 --default

FAQs

Warning! PATH is not properly set up, /Users/cloudolife/.rvm/gems/ruby-2.6.1/bin is not at first place.

1
2
3
4
5
6
7
8
9
$ rvm get stable
Warning! PATH is not properly set up, /Users/cloudolife/.rvm/gems/ruby-2.6.1/bin is not at first place.
Usually this is caused by shell initialization files. Search for PATH=... entries.
You can also re-add RVM to your profile by running: rvm get stable --auto-dotfiles
To fix it temporarily in this shell session run: rvm use ruby-2.6.1
To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
...
Error running 'command gem install /Users/cloudolife/.rvm/...
...

With option --auto-dotfiles to resolve it.

1
2
3
4
5
6
7
8
rvm get stable --auto-dotfiles
RVM version 1.29.12 (latest) is installed, yet version 1.29.12-next (master) is loaded.

Please open a new shell or run one of the following commands:

rvm reload
echo rvm_auto_reload_flag=1 >> ~/.rvmrc # OR for auto reload with msg
echo rvm_auto_reload_flag=2 >> ~/.rvmrc # OR for silent auto reload

Reference

[1] RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation - https://rvm.io/

[2] RVM: Ruby Version Manager - Installing RVM - https://rvm.io/rvm/install#installation

[3] Ruby Programming Language - https://www.ruby-lang.org/en/