How to Install Ruby on CentOS/RHEL 8

Channel: RedHat CentOS Linux
Abstract: Install Ruby Using RVM in CentOS 8 This will take a while. This would be a perfect time to take a coffee break as the rvm installs Ruby 2.7.1. Once th

Ruby is a dynamic, multi-purpose, free, and open-source programming language that is usually used for the development of web applications.

It’s a high-level programming language that enjoys a vibrant community of developers who help maintain and continually improve the language for better and more efficient code. Ruby can be used in diverse applications such as data analysis, custom database solutions and prototyping to mention a few.

In this article, you will learn how to install Ruby on CentOS 8 and RHEL 8 Linux.

There are 2 ways of installing Ruby:
  1. Installing Ruby via Appstream Repositories
  2. Installing Ruby via RVM Manager

We will shed light on how you install Ruby using the above-mentioned methods.

Install Ruby on CentOS 8 via Appstream Repository

To install Ruby using the AppStream repo, fire up your terminal and update the system’s packages and repositories by invoking the following dnf command.

$ sudo dnf update

Next, ensure the below-mentioned packages are installed before going ahead with Ruby.

$ sudo dnf install gnupg2 curl tar

Finally, install Ruby from the Appstream repositories.

$ sudo dnf install @ruby
Install Ruby on CentOS 8

Upon completion, verify the version of Ruby installed by running the command.

$ ruby --version
Verify Ruby Version in CentOS 8

From the output, we can see that we have installed Ruby 2.5.5 on our CentOS 8 system.

Install Ruby on CentOS 8 using the RVM Manager

Often abbreviated as RVM, Ruby Version Manager is a versatile command-line tool and package manager such as dnf that allows you to install and manage multiple Ruby environments.

To install rvm, you need to first download the RVM startup script as the root user. So, switch from the regular to root user and execute the following curl command.

# curl -sSL https://get.rvm.io | bash
Install RVM in CentOS 8

During the installation of the RVM script, a new group rvm is created. Additionally, you get a notification that the installer no longer adds users to the rvm group automatically. Users need to do this by themselves.

Therefore, once the installation is done, add the regular user to the rvm group as shown.

# usermod -aG rvm tecmint

Next, update the system environment variables by executing the command.

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

Then reload RVM.

# rvm reload
Reload RVM in CentOS 8

Next, install package requirements.

# rvm requirements
Install RVM Requirements in CentOS 8

Once you are done with the installation, you can now check the various versions of Ruby that are available for download using the command.

# rvm list known
RVM Available Ruby Versions

By the time of writing this guide, the latest version of Ruby is 2.7.1.

To install Ruby using the RVM manager run the command.

# rvm install ruby 2.7.1
Install Ruby Using RVM in CentOS 8

This will take a while. This would be a perfect time to take a coffee break as the rvm installs Ruby 2.7.1.

Once the installation is complete, verify the version of Ruby.

$ ruby --version
Check Ruby Version in CentOS 8

As seen from the output, the version of Ruby has changed to reflect the latest version which was installed by the RVM manager.

To make the above version the default version for Ruby, run the command.

# rvm use 2.7.1 --default
Set Ruby Default Version in CentOS 8

And that’s how you install Ruby on CentOS 8 and RHEL 8. We hope you will find it quite a breeze installing it on your system. Your feedback is most welcome.

Ref From: tecmint

Related articles