Ruby is the dynamic and open source programming language. Which focuses on coding simplicity and improve productivity. The first Ruby version 0.95 was release in 1995. After that several stable versions of Ruby were released in the past years. At the time of writing this tutorial, Ruby 2.7.0 is the latest stable release available for development.

Advertisement

This tutorial will help your to install required Ruby version on your Ubuntu 20.04 system. If your application release on Ruby 1.9 or 1.8 versions, We recommended to go with previous Ubuntu version.

Pre-Requisites

You must have shell access with sudo privileged account to your Ubuntu 20.04 system.

Now, Use one of the below 2 methods for installing Ruby languege on your system. We prefer to use Method 2 to install Ruby with RVM on Ubuntu 20.04 system.

Method 1 – Install Ruby from Default Repositories

The Ubuntu 20.04 official repositories contains the latest version of Ruby (ie. 2.7). Users need to start building application with Ruby 2.7.0 or existing applications’s supported 2.7 can install directly on their systems.

To install Ruby 2.7 on your Ubuntu system, Login to your system with sudo privileged account and execute the following commands:

sudo apt update 
sudo apt install ruby-full 

After the installation completed. Check the installed Ruby version by executing command:

ruby --version 

Output will be something like below.

ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]

Next, method will help you for installing Ruby using RVM on Ubuntu system.

Method 2 – Installing Ruby with RVM

RVM is known as Ruby Version Manager is a command-line tool for the installing and managing multiple Ruby versions on a single system. This tutorial will help you to install RVM on your Ubuntu system. Also install required or multiple Ruby versions and switch between them.

First, update the Apt cache and install few basic required packages:

sudo apt update 
sudo apt install curl gnupg2 
1. Install RVM

Now, Run the following commands to add the GPG key to your Ubuntu system. The second command will install latest RVM tool your Ubuntu system.

gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 3804BB82D39DC0E3 105BD0E739499BDB 
curl -sSL https://get.rvm.io | bash -s stable 

After installation, set and load the RVM environment variables to current session. Then install all the required packages dependencies for RVM on your system.

source /etc/profile.d/rvm.sh
rvm requirements

Output:

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.
2. Check Available Ruby Version

Now, find out the available Ruby version’s for your System. To get a list of all Ruby versions that can be installed with RVM, type:

rvm list known 

You will see a list of Ruby packages along with plugins supported specific integrations.

3. Install Required Ruby Version

Now, install the required Ruby version by running one of the following command. To install a different version, you must pass version number to the following command:

rvm install ruby-2.5           ## Install Ruby 2.5
rvm install ruby-2.7           ## Install Ruby 2.7

The above command will also set Ruby version as default version your installed.

Once the installation completed. Check the current default Ruby version by executing following command.

ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
4. Change Default Ruby Version

If the current default Ruby version is not suitable for you. You can change the default version by executing command as below. Make sure to change the Ruby version as per your requirements.

rvm use default 2.5         ## Set Ruby 2.5 as Default
rvm use default 2.7         ## Set Ruby 2.7 sa Default

Conclusion

In this tutorial, you have learned to install Ruby programming language on your Ubuntu 20.04 system.

Share.
Leave A Reply


Exit mobile version