How to Install Ruby on CentOS 8

Install Ruby on CentOS 8

In this article, we will have explained the necessary steps to install and configure Ruby on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Ruby Ruby is a dynamic, open source, object-oriented scripting language created with simplicity and productivity in mind. RVM (Ruby Version Manager) is a tool for installing and managing multiple Ruby versions on single operating systems.

Install Ruby on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum dnf epel-release
sudo dnf update

Step 2. Install Ruby on CentOS 8.

  • Installing Ruby from the CentOS repositories

Run the following command as root to install the ruby package:

sudo dnf install ruby

Once installed, check version:

ruby --version
  • Installing Ruby using Rbenv
curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

Before starting using rbenv we need to add $HOME/.rbenv/bin to our PATH:

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

The current latest stable version for Ruby is 2.7.1 at the time of writing this tutorial. Run below command to install Ruby:

rbenv install 2.7.1
rbenv global 2.7.1

To check if everything has been successful, just show the current version of ruby:

ruby -v
  • Installing Ruby with RVM
sudo dnf install curl gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel

Then, run the following commands to import the GPG keys and install RVM:

gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable

To start using RVM you need to run following command:

source ~/.rvm/scripts/rvm

Verify the installation:

ruby -v

Congratulation, you have learned how to install and configure Ruby on CentOS 8. If you have any question, please leave a comment below.