Ruby is a dynamic, interpreted, reflective, object-oriented, general-purpose programming language. According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. It supports multiple programming paradigms, including functional, object-oriented, and imperative. It also has a dynamic type system and automatic memory management.

In this guide, we will explain how to install Ruby on a CentOS 8 server.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can quickly deploy your cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is recommended that you update the system to the latest packages before beginning any significant installations. Issue the command below:

sudo yum update -y

We will be using two methods of installing Ruby on CentOS 7:

  • Installing Ruby from the YUM package manager.
  • Installing Ruby using Rbenv.

Installing Ruby from the YUM package manager
This method of installing Ruby would most likely not provide the latest version of Ruby. As at the time of writing this guide, the release is 2.5

Issue the command below to install the ruby package:

sudo yum install ruby

After installation, issue the command below to check the version:

ruby --version

Installing Ruby using Rbenv
Rbenv is a lightweight Ruby version management utility which allows you to switch Ruby versions easily.

Issue the command below to install the following dependencies which are required by the ruby-build tool:

sudo yum install git wget gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel

Next, issue the following command to install rbenv and ruby-build:

wget -q -O- | bash

Next, add $HOME/.rbenv/bin to our PATH by issuing the following commands:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

Next, issue the rbenv -v command to verify that the installation was successful:

 rbenv -v

To list all available Ruby versions issue the command below:

rbenv install -l

You can now install the latest stable version of Ruby and set it as our default version with:

rbenv install 2.7.0
rbenv global 2.7.0

After installation, issue the command below to check the version:

ruby --version