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.

[email protected]:/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:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

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

command curl -sSL | sudo gpg2 --import -
command curl -sSL | sudo gpg2 --import -

  • Here is the command output.

[email protected]:/home/ubuntu# curl -sSL | 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 | bash -s stable

  • Here is the command output.

[email protected]:/home/ubuntu# curl -sSL | bash -s stable
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/`
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/

  • To install all the required packages dependencies for RVM.

rvm requirements

  • Here is the command output.

[email protected]:/home/ubuntu# source /etc/profile.d/
[email protected]:/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.

[email protected]:/home/ubuntu# rvm list known
# MRI Rubies
[ruby-]1.8.7[-head] # security released on head
# for forks use: rvm install ruby-head-<name> --url --branch 2.2
# JRuby
# Rubinius

Step 5: To install the required Ruby version.

rvm install ruby-2.5
rvm install ruby-2.7

  • Here is the command output.

[email protected]:/home/ubuntu# rvm install ruby-2.7
Searching for binary rubies, this might take some time.
Found remote file
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/[email protected]
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.

[email protected]:/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
rvm use default 2.7

  • Here is the command output.

[email protected]:/home/ubuntu# rvm use default 2.7
Using /usr/local/rvm/gems/ruby-2.7.2

Leave a Reply

Your email address will not be published.