How to install and configure Ruby on CentOS 7

Ruby is one of the most popular languages ​​today. Ruby has neat syntax and is the language behind Ruby on Rails’s powerful framework.

In this tutorial we’ll show you three different ways to install Ruby on CentOS. Each of them has its own benefits, you can choose the installation method that suits you the most.

Preparation

Before starting the tutorial, make sure you are logged in as a user with sudo privileges.

How to install Ruby from CentOS repository

The easiest way to install Ruby on your CentOS system is via yum Group manager. At the time of writing, the version in the CentOS repository is 2.0.0 Somewhat outdated or outdated

To install Ruby from default CentOS repositories, follow these steps:

  1. Install Ruby by typing:
    sudo yum install ruby
  2. To verify that the installation was successful, run the following command that will print your version of Ruby:
    ruby --version

    The output will look like this:

    ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

Install Ruby with Rbenv

Rbenv is a Ruby version management tool that allows you to easily switch between Ruby versions.

We will also install plugins ruby-build Which extends the basic functionality of Rbenv, allowing us to easily install any version of Ruby from source.

To install Ruby with Rbenv, follow these steps:

  1. First, install the required dependencies with ruby-build:
    sudo yum install git-core zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison curl sqlite-devel
  2. Next, run the next curl command to install rbenv And the ruby-build:
    curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

    The script will clone the rbenv and ruby-build repositories from GitHub to a directory ~/.rbenv. The installed script also calls other scripts that will try to verify the installation. The script output will look like this:

    Install Ruby and Repnf

    As you can see in the above output, before we start using rbenv, we need to add an $HOME/.rbenv/bin To the right track.
    If you use bash, run:

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

    If you use Zsh, run:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
    echo 'eval "$(rbenv init -)"' >> ~/.zshrc
    source ~/.zshrc
  3. Now we have successfully installed rbenv On the system, we can also easily install the latest stable version of Ruby and make it the default by:
    rbenv install 2.5.1
    rbenv global 2.5.1

    To see a list of all available Ruby versions, you can use: rbenv install -l

    Check that Ruby is installed correctly by printing out the version number:

    ruby -v

    Produce:

    ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

Install Ruby with RVM

RVM (Ruby Publications Manager) Is a command line tool that allows you to easily install, manage and work with multiple Ruby environments.

To install Ruby with RVM, follow these steps:

  1. First, install all the dependencies the RVM utility needs to build Ruby from source:
    sudo yum install curl gpg gcc gcc-c++ make patch autoconf automake bison libffi-devel libtool patch readline-devel sqlite-devel zlib-devel openssl-devel
  2. Run the following command to install RVM:
    sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    curl -sSL https://get.rvm.io | bash -s stable

    Install ruby ​​rvm
    To start using RVM, you need to run the following command:

    source ~/.rvm/scripts/rvm
  3. Install the latest stable version of Ruby with RVM and set it as default:
    rvm install 2.5.1
    rvm use 2.5.1 --default

    Check that Ruby is installed correctly by printing out the version number:

    ruby -v

    Produce:

    ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

For more information on how to manage Ruby installation, visit the RVM documentation page.

Conclusion

We have shown you three different ways to install Ruby on a CentOS server. Which method you choose depends on your needs and preferences.

By installing Ruby using a Rbenv And the RVM It gives you more flexibility to add and remove different versions of Ruby on a per user basis.

.

Source link

Leave a Reply

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