How to Install Ruby on CentOS 8
3 min read
Ruby is one of the most popular languages today. It has an elegant syntax, and it is the language behind the Ruby on Rails framework.
In this article, we will explore different ways to install Ruby on CentOS 8.
We’ll show how to install Ruby from the default CentOS 8 repositories and using the Rbenv and RVM scripts. Choose the installation method that is most appropriate for your setup and environment.
Installing Ruby from the CentOS repositories
This is the easiest method for installing Ruby on CentOS. At the time of writing, the version in the standard CentOS repositories is 2.5.5.
Run the following command as root or user with sudo privileges to install the
sudo dnf install ruby
Once the installation is completed, you can verify that it was successful by printing the Ruby version:
The output will look something like this:
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
Your Ruby version may differ from the one shown above.
That’s it! You have successfully installed Ruby on your CentOS system, and you can start using it.
Install Ruby with Rbenv
Rbenv is a lightweight Ruby version management utility that allows you to easily switch Ruby versions.
We’ll use the
ruby-build plugin that extends the core functionality of Rbenv and allow you to install any Ruby version from source.
Start by installing git and other dependencies required to build Ruby from the source:
sudo dnf install git wget gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
Run the following command to install both
wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
Before starting using
rbenv, you need to add
$HOME/.rbenv/bin to your
If you are using Bash, type:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
If you are using Zsh type:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
rbenv -v command to ensure that installation was successful:
To get a list of all Ruby versions that can be installed with
rbenv install -l
For example, if you want to install the Ruby 2.7.0 and set it as default version you would type:
rbenv install 2.7.0
rbenv global 2.7.0
Verify that Ruby was properly installed by printing the version number:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
Installing Ruby with RVM
RVM (Ruby Version Manager) is a command-line tool that allows you to install, manage, and work with multiple Ruby environments.
First, install the dependencies required for
rvm to build Ruby from source:
sudo dnf install curl gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
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 the following
To get a list of all known Ruby versions type:
rvm list known
If for example, you want to install Ruby 2.6 and set it as the default version you would issue the following commands:
rvm install 2.6
rvm use 2.6 --default
Verify the installation:
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
For more information about how to manage your Ruby installations with RVM visit the RVM Documentation page .
We have shown you three different ways to install Ruby on your CentOS 8 server. The method you choose depends on your requirements and preferences. Even though installing the packaged version from the CentOS repository is easier, the Rbenv and RVM methods give you more flexibility for adding and removing different Ruby versions on a per user basis.
If you have any questions or feedback, feel free to comment below.