Ruby is one of the most popular languages today. It has a concise syntax and is the language behind the Ruby on Rails framework.
In this article, we will explore different ways to install Ruby on CentOS 8.
We will show how to install Ruby through CentOS 8 source repositories, using Rbenv, and using RVM scripts. Choose the installation method that best suits your environment.
This is the easiest way to install on CentOS. At the time of writing, the Ruby version on the standard CentOS source repository is 2.5.5.
As root or another user with sudo privileges, run the following command to install the ruby
package:
sudo dnf install ruby
Once the installation is complete, you can verify whether Ruby is successfully installed by printing the Ruby version number.
ruby --version
The output should look like this:
ruby 2.5.5p157(2019-03-15 revision 67260)[x86_64-linux]
Your Ruby version number may be different from the one shown above.
that's it. You have successfully installed Ruby on your CentOS system and can start using it.
Rbenv is a lightweight Ruby version management tool that allows you to switch Ruby versions easily.
We will use the ruby-build
plugin to extend the core functionality of Rbenv and allow you to install any Ruby version from source.
Install git and other dependencies necessary to compile Ruby from 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 rbenv
and ruby-build
:
wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O-| bash
This script will clone the rbenv
and ruby-build
source code from Github to the ~/.rbenv
directory.
Before you start using rbenv
, you need to add $HOME/.rbenv/bin
to your PATH.
If you are using Bash, enter:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>>~/.bashrc
echo 'eval "$(rbenv init -)"'>>~/.bashrc
source ~/.bashrc
If you are using Zsh, enter:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'>>~/.zshrc
echo 'eval "$(rbenv init -)"'>>~/.zshrc
source ~/.zshrc
Run the rbenv -v
command to ensure that the installation is successful:
rbenv -v
The output is as follows:
rbenv 1.1.2-17-g7795476
To get all installable Ruby versions installed via rbenv
, type:
rbenv install -l
For example, if you want to install Ruby 2.7.0 and set it as the default version, you can enter:
rbenv install 2.7.0
rbenv global 2.7.0
Print the Ruby version number to verify that Ruby is installed correctly:
ruby -v
Output:
ruby 2.7.0p0(2019-12-25 revision 647ee6f091)[x86_64-linux]
RVM (Ruby Version Manager) is a command line tool that allows you to install, manage and use multiple Ruby environments.
First, install the dependencies necessary for rvm
to build Ruby from source code:
sudo dnf install curl gcc bzip2 openssl-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel
Run the following command to import the GPG public key 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 source command:
source ~/.rvm/scripts/rvm
To get all known Ruby versions, type:
rvm list known
For this example, if you want to install Ruby 2.6 and set it as the default version, you can trigger the following command:
rvm install 2.6
rvm use 2.6--default
Verify the installation:
ruby -v
The output is as follows:
ruby 2.6.3p62(2019-04-16 revision 67580)[x86_64-linux]
For more information on how to use RVM to manage Ruby installations, please visit RVM Documentation Page.
We have shown you three different ways to install Ruby on your CentOS 8 server. You choose one of these methods according to your requirements and preferences. Even though the way to install Ruby through CentOS source repositories is relatively simple, Rbenv and RVM methods give you more choices. You can add or remove different Ruby versions for each user.
Recommended Posts