You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In this guide, we will look at how to Install Ruby on Ubuntu 18.04 LTS. Ruby is a dynamic, open source, object-oriented scripting language created with simplicity and productivity in mind.

The easiest way to Install Ruby on Ubuntu 18.04 is from a PPA repository. For this, we will use the Brightbox PPA repository. Brightbox has been providing optimized Ruby packages for Ubuntu for years.

We will also consider other methods of installation Ruby on Ubuntu 18.04:

  • Install Ruby using RVM
  • Install Ruby using Rbenv

Install Ruby from PPA repository

I like the Brightbox PPA repository because it gives you the flexibility to install any version of Ruby they maintain.

Add PPA repository to your Ubuntu 18.04 system using the commands:

sudo apt -y install software-properties-common
sudo apt-add-repository ppa:brightbox/ruby-ng

After the repo is added, update your packages list

sudo apt update

Then install the version of Ruby you want. For me, I’m installing Ruby 2.5

$ sudo apt install ruby2.5
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
1 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Need to get 56.6 kB of archives.
After this operation, 2,048 B of additional disk space will be used.
Get:1 bionic/main amd64 ruby2.5 amd64 2.5.3-1bbox1~bionic1 [56.6 kB]
Fetched 56.6 kB in 1s (66.2 kB/s)  
(Reading database ... 141513 files and directories currently installed.)
Preparing to unpack .../ruby2.5_2.5.3-1bbox1~bionic1_amd64.deb ...
Unpacking ruby2.5 (2.5.3-1bbox1~bionic1) over (2.5.1-1ubuntu1.1) ...
Setting up ruby2.5 (2.5.3-1bbox1~bionic1) ...
update-alternatives: using /usr/bin/gem2.5 to provide /usr/bin/gem (gem) in auto mode
update-alternatives: using /usr/bin/ruby2.5 to provide /usr/bin/ruby (ruby) in auto mode
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

Among the Ruby packages maintained by Brightbox – 2.4, 2.3, 2.2, 2.1, 2.0, 1.9.3, and 1.8.7. Example to install Ruby 2.4, use:

sudo apt install ruby2.4

Once installed, check version:

$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

Install Ruby using RVM

You can also install Ruby using RVM. RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

Import RVM GPG key:

sudo gpg --keyserver hkp:// --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

Then install RVM on Ubuntu 18.04 by running the command:

curl -L | sudo bash -s stable
source /etc/profile.d/

You can check version:

$ rvm --version
rvm 1.29.6 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin []

Install dependencies by running the command:

rvm requirements run

Install Ruby like below:

# rvm install 2.5.1
Warning, new version of rvm available '1.29.7', you are using older version '1.29.6'.
You can disable this warning with:    echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable  auto-update  with:    echo rvm_autoupdate_flag=2 >> ~/.rvmrc
Searching for binary rubies, this might take some time.
Found remote file
Checking requirements for ubuntu.
Requirements installation successful.
ruby-2.5.1 - #configure
ruby-2.5.1 - #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     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--    100 17.8M  100 17.8M    0     0  1059k      0  0:00:17  0:00:17 --:--:-- 1303k
ruby-2.5.1 - #validate archive
ruby-2.5.1 - #extract
ruby-2.5.1 - #validate binary
ruby-2.5.1 - #setup
ruby-2.5.1 - #gemset created /usr/local/rvm/gems/[email protected]
ruby-2.5.1 - #importing gemset /usr/local/rvm/gemsets/global.gems..................................
ruby-2.5.1 - #generating global wrappers.......
ruby-2.5.1 - #gemset created /usr/local/rvm/gems/ruby-2.5.1
ruby-2.5.1 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.5.1 - #generating default wrappers.......

To list available Ruby interpreters, use:

rvm list known

That’s all. You now have Ruby installed on Ubuntu 18.04 system.

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF


Please enter your comment!
Please enter your name here