How to Install Ruby on CentOS 8

[ad_1]

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 ruby package:

sudo dnf install ruby

Once the installation is completed, you can verify that it was successful by printing the Ruby version:

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 rbenv and ruby-build:

wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash

The script will clone both rbenv
and ruby-build
repositories from GitHub to ~/.rbenv directory.

Before starting using rbenv, you need to add $HOME/.rbenv/bin to your PATH
.

If you are using Bash, type:

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

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

Run the rbenv -v command to ensure that installation was successful:

rbenv -v
rbenv 1.1.2-17-g7795476

To get a list of all Ruby versions that can be installed with rbenv enter:

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.0rbenv global 2.7.0

Verify that Ruby was properly installed by printing the version number:

ruby -v
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 7D2BAF1CF37B13E2069D6956105BD0E739499BDBcurl -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 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.6rvm use 2.6 --default

Verify the installation:

ruby -v
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
.

Conclusion #

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.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.