How to install Ruby version manager (RVM) on Ubuntu

Applications for Ruby often require different versions of Ruby, and only one version is usually installed from packages, and not necessarily the latest. Particular difficulties arise when different applications on the same server require different versions of Ruby. To eliminate this drawback, there is Ruby Version Manager (RVM), which deals with Ruby version control, physically separates versions, and also allows you to create separate gemsets for each version of Ruby (within each version of Ruby you can have several sets of gems).

Ruby 2

You can install RVM for a specific user or for all users. If the installation is done for all users, then everything is done from root or using sudo. Let’s start the installation of RVM (the installation process for all users is described) in this post.

Install all the package dependencies:
sudo aptget install curl git
Set the GPG key for the root user:

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

or

curl -sSL https://rvm.io/mpapis.asc | sudo gpg –import –
curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg –import –

Download and run the RVM installation script:

\curl -sSL https://get.rvm.io | bash -s stable –ruby

Run command:

source /home/username/.rvm/scripts/rvm

Now add all the users who need RVM to the rvm group:
usermod a G rvm username
Ruby version manager installed. Now you can install the desired version of Ruby. To see all available versions of Ruby, use the command:
rvm list known
To install the necessary version of Ruby, use the command:
rvm install Ruby_version
To see all installed versions of Ruby, use the command:
rvm list
To select the default version of Ruby, use the command:
rvm use ruby Ruby_version default

Create a gemsets set (all gemsets are created for a specific version of Ruby):

rvm use Ruby_version@set_name –create

View available gemsets:

rvm gemset list

Use gemset test for Ruby 2.6.0 by default:

rvm use 2.6.0@test default

Clear gemset:

rvm gemset empty gemset_name

Remove gemset:
rvm gemset delete gemset_name