In this article, we will see how to install RVM on Ubuntu. Ruby Version Manager (RVM) is a free and open source command-line tool that facilitates the management of multiple Ruby environments and versions on a single machine. It's widely used by Ruby developers for its ability to handle different Ruby versions and gemsets (collections of Ruby libraries or gems), making it easier to work on multiple projects with varying dependencies. It is easy to install and use in almost all the famous platforms. Here we will see the steps to install RVM (Ruby Version Manager) on Ubuntu based linux systems.
Key Features
- Multiple Ruby Environments: RVM allows users to install, manage, and work with multiple Ruby environments, from interpreters to sets of gems. This is particularly useful when different projects require different Ruby versions or gem dependencies.
- Gemset Management: It provides the ability to create and use gemsets, which are isolated environments for gems. This ensures that the gems required for one project do not interfere with those needed for another.
- Easy Installation and Switching: RVM makes it easy to install multiple versions of Ruby and switch between them as needed. This is done through simple command-line commands.
- Project-specific Environments: RVM allows you to specify a Ruby version and a set of gems for each project, which can be automatically loaded when you enter the project directory.
- Integration with Shell: It integrates with your shell (like Bash or Zsh) and can automatically switch Ruby versions and gemsets based on directory settings.
- Support for Various Ruby Implementations: RVM supports different Ruby implementations, such as MRI (Matz's Ruby Interpreter), JRuby, and Rubinius.
- Source and Binary Rubies: It can install Ruby either by compiling from source or by using pre-compiled binary distributions, offering flexibility based on user needs and system capabilities.
- Dependency Management: RVM helps manage dependencies required for different Ruby versions, ensuring a smoother installation process.
How to Install RVM (Ruby Version Manager) on Ubuntu
Also Read: How to Install RQuantLib(R Interface to QuantLib Library) on Linux
Step 1: Prerequisites
a) You should have a running Ubuntu
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility available in your Server.
Step 2: Update Your Server
From time to time, Ubuntu releases security fixes and bug fixes which needs to be installed in the system to make system secure and stable. This can be easily done by using sudo apt update && sudo apt upgrade
command as shown below.
itsfosslinux@ubuntu:~$ sudo apt update && sudo apt upgrade
Step 3: Install software-properties-common
As a requirement, you have to make sure software-properties-common
package installed in your system. It can be installed by running sudo apt-get install software-properties-common
command as shown below.
itsfosslinux@ubuntu:~$ sudo apt-get install software-properties-common
[sudo] password for itsfosslinux:
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.99.9.12).
software-properties-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Also Read
Step 4: Add PPA Repo
Since rvm package is not available from default ubuntu repo, you have to add the required PPA repo to download and install the package. To add, run sudo apt-add-repository -y ppa:rael-gc/rvm
command as shown below.
itsfosslinux@ubuntu:~$ sudo apt-add-repository -y ppa:rael-gc/rvm
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:5 https://dl.winehq.org/wine-builds/ubuntu focal InRelease [8,041 B]
Ign:6 https://pkg.jenkins.io/debian-stable binary/ InRelease
Hit:7 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Hit:8 https://download.sublimetext.com apt/stable/ InRelease
Hit:9 https://pkg.jenkins.io/debian-stable binary/ Release
Get:10 https://repositories.timber.io/public/vector/deb/ubuntu focal InRelease [4,947 B]
Hit:11 https://ngrok-agent.s3.amazonaws.com buster InRelease
Hit:12 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 InRelease
Hit:13 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Get:14 https://dl.winehq.org/wine-builds/ubuntu focal/main i386 Packages [452 kB]
Get:15 https://dl.winehq.org/wine-builds/ubuntu focal/main amd64 Packages [451 kB]
Hit:17 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:18 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Hit:19 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
Hit:20 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease
Hit:21 http://ppa.launchpad.net/mojo-maintainers/ppa/ubuntu focal InRelease
Get:22 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal InRelease [18.1 kB]
Hit:23 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Get:24 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal/main amd64 Packages [1,316 B]
Get:25 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal/main i386 Packages [596 B]
Get:26 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal/main Translation-en [940 B]
Fetched 1,050 kB in 7s (153 kB/s)
Reading package lists... Done
Step 5: Update Package Cache
After adding PPA repo, you have to update the package cache by running sudo apt-get update
command. This will refreshes the list of available packages and their versions by querying the repositories in its sources list, including the newly added PPA.
itsfosslinux@ubuntu:~$ sudo apt-get update [sudo] password for itsfosslinux: Hit:1 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:4 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease Hit:5 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease Hit:6 https://dl.google.com/linux/chrome/deb stable InRelease Hit:7 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease Hit:8 http://ppa.launchpad.net/libreoffice/ppa/ubuntu focal InRelease Hit:9 https://ngrok-agent.s3.amazonaws.com buster InRelease Hit:10 http://ppa.launchpad.net/mojo-maintainers/ppa/ubuntu focal InRelease Hit:11 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal InRelease Ign:12 https://pkg.jenkins.io/debian-stable binary/ InRelease Get:13 https://repositories.timber.io/public/vector/deb/ubuntu focal InRelease [4,947 B] Hit:14 https://pkg.jenkins.io/debian-stable binary/ Release Hit:15 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease Hit:16 https://download.sublimetext.com apt/stable/ InRelease Hit:17 http://in.archive.ubuntu.com/ubuntu focal InRelease Get:18 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Hit:19 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease Hit:20 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/focal pgadmin4 InRelease Fetched 119 kB in 30s (3,947 B/s) Reading package lists... Done
Step 6: Install RVM (Ruby Version Manager)
In the next step, you can install rvm from the added repo by using sudo apt-get install rvm
command as shown below. This will download and install the package along with all its required dependencies.
itsfosslinux@ubuntu:~$ sudo apt-get install rvm Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: gawk libgdbm-dev libsqlite3-dev libyaml-dev sqlite3 Suggested packages: gawk-doc sqlite3-doc libyaml-doc The following NEW packages will be installed: gawk libgdbm-dev libsqlite3-dev libyaml-dev rvm sqlite3 0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded. Need to get 3,126 kB of archives. After this operation, 12.1 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ppa.launchpad.net/rael-gc/rvm/ubuntu focal/main amd64 rvm all 1.29.12-1 [1,013 kB] Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 gawk amd64 1:5.0.1+dfsg-1ubuntu0.1 [415 kB] Get:3 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libgdbm-dev amd64 1.18.1-5 [83.4 kB] Get:4 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 libsqlite3-dev amd64 3.31.1-4ubuntu0.5 [697 kB] Get:5 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libyaml-dev amd64 0.2.2-1 [58.2 kB] Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 sqlite3 amd64 3.31.1-4ubuntu0.5 [860 kB] Fetched 3,126 kB in 3s (1,138 kB/s) Selecting previously unselected package gawk. ..........................................................
Step 7: Export PATH
In most cases, rvm will get installed in either /opt
or /usr
path which is generally not visible to the system. So to detect the rvm binaries, you have to add the binary path in PATH
environment variable. For example, in our case as you noticed above, rvm binaries installed on /usr/share/rvm/bin
path we need to add this path in PATH
environment variable using export PATH=$PATH:/usr/share/rvm/bin
command.
But remember this is just a temporary arrangement, to make the changes permanent you have to add the path at the end of either ~/.bashrc
or ~/.profile
file and then logout and login to update the changes. You can also update the changes without logging out the system using source
command.
itsfosslinux@ubuntu:~$ export PATH=$PATH:/usr/share/rvm/bin
Step 8: Check version
You can verify the current installed version of rvm by running rvm --version
command as shown below.
itsfosslinux@ubuntu:~$ rvm --version rvm 1.29.12 (manual) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
Step 9: Set rvmsudo_secure_path
If you are using non-root user, then you have to use rvmsudo
command to perform rvm
operation with elevated privileges while preserving the rvm environment or else you will end up getting "sudo: rvm: command not found"
error on the output. To use rvmsudo
command, you need to first check if secure_path
exists in /etc/sudoers
. If it exists, then you have to set rvmsudo_secure_path
to 1
or else to 0
. For example, in our case secure_path
exists in /etc/sudoers
file so we are setting rvmsudo_secure_path
to 1
as shown below.
itsfosslinux@ubuntu:~$ export rvmsudo_secure_path=1
Step 10: Install Ruby
Then to install the latest stable version of ruby interpreter, use rvmsudo rvm install ruby
command as shown below. You can also install a specific version of ruby interpreter by specifying that version during installation. You can check the list of available versions to install by using rvm list known
command.
itsfosslinux@ubuntu:~$ rvmsudo rvm install ruby Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-3.0.0.tar.bz2 Checking requirements for ubuntu. Requirements installation successful. ruby-3.0.0 - #configure ruby-3.0.0 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 26.6M 100 26.6M 0 0 977k 0 0:00:27 0:00:27 --:--:-- 880k Downloaded archive checksum did not match, archive was removed! If you wish to continue with not matching download add '--verify-downloads 2' after the command. Downloading https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-3.0.0.tar.bz2 failed. Mounting remote ruby failed with status 2, trying to compile. Checking requirements for ubuntu. Requirements installation successful. Installing Ruby from source to: /usr/share/rvm/rubies/ruby-3.0.0, this may take a while depending on your cpu(s)... ruby-3.0.0 - #downloading ruby-3.0.0, this may take a while depending on your connection... ruby-3.0.0 - #extracting ruby-3.0.0 to /usr/share/rvm/src/ruby-3.0.0..... ruby-3.0.0 - #configuring......................................................................... ruby-3.0.0 - #post-configuration.. ruby-3.0.0 - #compiling.......................................................................................... ruby-3.0.0 - #installing..................... ruby-3.0.0 - #making binaries executable... Installed rubygems 3.2.3 is newer than 3.0.9 provided with installed ruby, skipping installation, use --force to force installation. ruby-3.0.0 - #gemset created /usr/share/rvm/gems/ruby-3.0.0@global ruby-3.0.0 - #importing gemset /usr/share/rvm/gemsets/global.gems................................................................ ruby-3.0.0 - #generating global wrappers........ ruby-3.0.0 - #gemset created /usr/share/rvm/gems/ruby-3.0.0 ruby-3.0.0 - #importing gemsetfile /usr/share/rvm/gemsets/default.gems evaluated to empty gem list ruby-3.0.0 - #generating default wrappers........ ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-3.0.0 - #complete Ruby was built without documentation, to build it run: rvm docs generate-ri
Step 11: Remove Ruby
If you want to remove ruby interpreter then run rvmsudo rvm remove ruby
command as shown below.
itsfosslinux@ubuntu:~$ rvmsudo rvm remove ruby
[sudo] password for itsfosslinux:
ruby-3.0.0 - #removing src/ruby-3.0.0..
ruby-3.0.0 - #removing rubies/ruby-3.0.0..
ruby-3.0.0 - #removing gems....
awk: fatal: cannot open file `/usr/share/rvm/config/alias' for reading (No such file or directory)
ruby-3.0.0 - #removing wrappers....
ruby-3.0.0 - #removing environments....
Step 12: Check all Available Options
To check all the options available with rvm utility, use rvm help
command as shown below.
itsfosslinux@ubuntu:~$ rvm help
Ruby enVironment Manager 1.29.12 (manual) (c) 2009-2020 Michal Papis, Piotr Kuczynski, Wayne E. Seguin
Usage:
rvm [--debug][--trace][--nice] <command> <options>
for example:
rvm list # list installed interpreters
rvm list known # list available interpreters
rvm install <version> # install ruby interpreter
rvm use <version> # switch to specified ruby interpreter
rvm remove <version> # remove ruby interpreter (alias: delete)
rvm get <version> # upgrade rvm: stable, master
.................................................
Step 13: Uninstall RVM (Ruby Version Manager)
Once you are done using rvm, you can remove it from your system by using sudo apt-get remove rvm
command as shown below. You can also remove all the dependent packages by using --auto-remove option
with below command.
itsfosslinux@ubuntu:~$ sudo apt-get remove rvm [sudo] password for itsfosslinux: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libgdbm-dev libsqlite3-dev libyaml-dev sqlite3 Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: rvm 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 4,772 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 294468 files and directories currently installed.) Removing rvm (1.29.12-1) ... Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby) Removing rvm wrappers in /usr/share/rvm/bin Hai! Removing /usr/share/rvm /usr/share/rvm has been removed. Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still. Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation. Also make sure to remove `rvm` group if this was a system installation. Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).
Finally remove the repo by using sudo apt-add-repository --remove ppa:rael-gc/rvm
command as shown below.
itsfosslinux@ubuntu:~$ sudo apt-add-repository --remove ppa:rael-gc/rvm
RVM (http://rvm.io) is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
Please, check install instructions here: https://github.com/rvm/ubuntu_rvm
More info: https://launchpad.net/~rael-gc/+archive/ubuntu/rvm
Press [ENTER] to continue or Ctrl-c to cancel removing it.