Steps to Install Ruby on Ubuntu 20.04 LTS

Ruby is a free & open source programming language. It helps on coding simplicity and improve productivity. It is used for building web applications.

RVM stand for Ruby Version Manage, is a command line tool. It is used for the installing and managing multiple Ruby versions on a single system. We can install required Ruby version or switch on different Ruby version.

There are some steps to install Ruby on ubuntu system.

  • Install Ruby using ubuntu repository.
  • Install Ruby with RVM.

Step 1: Update the System.

apt-get update

Step 2: Install Ruby on system.

apt install ruby-full

  • Check the ruby version.

ruby --version

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]

Step 3: Install Ruby with RVM.

  • Update the system.

apt-get update

  • Install the required packages:

apt install curl gnupg2

Step 4: Install RVM.

  • Add the GPG key to system.

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

or if it fails: then run any one command for add gpg key:

command curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg2 --import -

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# curl -sSL https://rvm.io/pkuczynski.asc | sudo gpg2 --import -
gpg: key 105BD0E739499BDB: public key "Piotr Kuczynski <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1

  • To install the latest RVM tool.

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

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made Fri Jan 15 18:46:22 2021 UTC
gpg: using RSA key 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: Good signature from "Piotr Kuczynski <[email protected]>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D 6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.12.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
* Please do NOT forget to add your users to the rvm group.
The installer no longer auto-adds root or users to the rvm group. Admins must do this.
Also, please note that group memberships are ONLY evaluated at login time.
This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM 🙏

  • To set and load the RVM environment variables.

source /etc/profile.d/rvm.sh

  • To install all the required packages dependencies for RVM.

rvm requirements

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# source /etc/profile.d/rvm.sh
root@ip-172-31-18-32:/home/ubuntu# rvm requirements
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, libreadline-dev, libssl-dev................................
Requirements installation successful.

  • To list the available Ruby version.

rvm list known

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head
# for forks use: rvm install ruby-head-<name> --url https://github.com/github/ruby.git --branch 2.2
# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.14.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.107]
rbx-4[.20]
rbx-5[.0]
rbx-head

Step 5: To install the required Ruby version.

rvm install ruby-2.5
or
rvm install ruby-2.7

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# rvm install ruby-2.7
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.2.tar.bz2
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.7.2 - #configure
ruby-2.7.2 - #download
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21.3M 100 21.3M 0 0 6679k 0 0:00:03 0:00:03 --:--:-- 6677k
ruby-2.7.2 - #validate archive
ruby-2.7.2 - #extract
ruby-2.7.2 - #validate binary
ruby-2.7.2 - #setup
ruby-2.7.2 - #gemset created /usr/local/rvm/gems/ruby-2.7.2@global
ruby-2.7.2 - #importing gemset /usr/local/rvm/gemsets/global.gems..................................
ruby-2.7.2 - #generating global wrappers........
ruby-2.7.2 - #gemset created /usr/local/rvm/gems/ruby-2.7.2
ruby-2.7.2 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.7.2 - #generating default wrappers........

  • Check the ruby version.

ruby --version

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# ruby --version
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]

Step 6: To change the default Ruby version.

rvm use default 2.5
or
rvm use default 2.7

  • Here is the command output.

root@ip-172-31-18-32:/home/ubuntu# rvm use default 2.7
Using /usr/local/rvm/gems/ruby-2.7.2

Leave a Reply