How to install Ruby on Ubuntu 20.04 LTS
Hi Friends, in this post we will learn how we can install Ruby on Ubuntu 20.04 LTS. And we will show how we can install Ruby Version Manager (RVM) also.
RVM is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
Prerequisite
- you should have sudo or root level access
Standalone Installation of Ruby
There are two methods to install the ruby software on the server. in this post, we will follow both methods. so let’s start with standalone.
Install Ruby
# sudo apt-get install ruby
Check Version
# ruby -v
Output
root@linuxfork:~# ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu] root@linuxfork:~#
Install RVM (Ruby Version Manager)
RVM will help us to switch the version of Ruby at any time. It allows flexibility to us.
Note:- If you already have installed ruby on machine then first remove it.
# apt-get autoremove ruby
Download and Install RVM
# curl -L https://get.rvm.io | bash -s stable
Note:- If you are getting error gpg: Can’t check signature: No public key then first import the public key then run the above command.

root@linuxfork:~# curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg --import - gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported gpg: Total number processed: 1 gpg: imported: 1
RVM uses Linux users for access control.so we need to add a user to the rvm group. we will add it using vim editor directly to the file /etc/group
# vim /etc/group
Add a user in the group rvm as per below and save and quite by pressing esc :wq!
rvm:x:1001:linuxfork
Now, we need to logout and relogin to the server otherwise below error will show.

Installing Ruby with RVM
Now, we can install ruby using RVM command-line tool.
sysadmin@linuxfork:~$ rvm install ruby
Output
sysadmin@linuxfork:~$ 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-2.7.0.tar.bz2 Checking requirements for ubuntu. Installing requirements for ubuntu. Updating system... Installing required packages: g++, gcc, autoconf, automake, bison, libc6-dev, libffi-dev, libgdbm-dev, libncurses5-dev, libsqlite3-dev, libtool, libyaml-dev, make, pkg-config, sqlite3, zlib1g-dev, libgmp-dev, libreadline-dev, libssl-dev................................ Requirements installation successful. ruby-2.7.0 - #configure ruby-2.7.0 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 21.3M 100 21.3M 0 0 5970k 0 0:00:03 0:00:03 --:--:-- 5970k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.7.0 - #validate archive ruby-2.7.0 - #extract ruby-2.7.0 - #validate binary ruby-2.7.0 - #setup ruby-2.7.0 - #gemset created /usr/local/rvm/gems/ruby-2.7.0@global ruby-2.7.0 - #importing gemset /usr/local/rvm/gemsets/global.gems.................................. ruby-2.7.0 - #generating global wrappers....... ruby-2.7.0 - #gemset created /usr/local/rvm/gems/ruby-2.7.0 ruby-2.7.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.7.0 - #generating default wrappers....... sysadmin@linuxfork:~$
Install Specific Version of Ruby
sysadmin@linuxfork:~$ rvm install 2.6.6
Output
sysadmin@linuxfork:~$ rvm install 2.6.6 Searching for binary rubies, this might take some time. Found remote file https://rubies.travis-ci.org/ubuntu/20.04/x86_64/ruby-2.6.6.tar.bz2 Checking requirements for ubuntu. Installing requirements for ubuntu. Updating system... Installing required packages: libssl-dev.... Requirements installation successful. ruby-2.6.6 - #configure ruby-2.6.6 - #download % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 100 19.9M 100 19.9M 0 0 3825k 0 0:00:05 0:00:05 --:--:-- 6239k No checksum for downloaded archive, recording checksum in user configuration. ruby-2.6.6 - #validate archive ruby-2.6.6 - #extract ruby-2.6.6 - #validate binary ruby-2.6.6 - #setup ruby-2.6.6 - #gemset created /usr/local/rvm/gems/ruby-2.6.6@global ruby-2.6.6 - #importing gemset /usr/local/rvm/gemsets/global.gems.................................. ruby-2.6.6 - #generating global wrappers....... ruby-2.6.6 - #gemset created /usr/local/rvm/gems/ruby-2.6.6 ruby-2.6.6 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list ruby-2.6.6 - #generating default wrappers....... sysadmin@linuxfork:~$
Now, we have two version of ruby 2.7 and 2.6 on the server.
We can switch between these two version of ruby using rvm command-line tool.
sysadmin@linuxfork:~$ rvm use 2.7
Output
sysadmin@linuxfork:~$ ruby -v ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux] sysadmin@linuxfork:~$ rvm use 2.7 Using /usr/local/rvm/gems/ruby-2.7.0 sysadmin@linuxfork:~$ ruby -v ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux] sysadmin@linuxfork:~$
That’s all in this post, hope it will help all of you.
I am a professional Cloud Engineer and founder of LinuxFork. I am working on Infrastructure Deployment and focusing on the integration of open source technologies with the Cloud. I am an avid Linux lover and open source enthusiast. mostly, I am working with Redhat and Ubuntu Linux in the production environment. apart from this I always believe in knowledge sharing.