• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Ruby on CentOS 7

Written by Admin, Updated On July 26, 2019
centos, ruby
How To Install Ruby on CentOS 7

Ruby is one of the most popular language nowadays. Ruby is used for web applications and also for games etc. In this tutorial, described steps to install Ruby on CentOS 7 system. It’s used with Ruby on Rails framework.

Prerequisites#

Before you start installation, make sure that you should logged in with non-root user account with sudo privileges.

Install Ruby on CentOS#

Fastest and easy way to install Ruby package is using yum package manager . Ruby is available in CentOS repositories. Below given steps to install Ruby from the default CentOS repositories:

Install Ruby package using below command:

sudo yum install ruby

On the completion of installation you can verify it by typing below command and it will print the version of installed Ruby.

ruby --version

It should look like as below:

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

Install Ruby using Rbenv#

Rbenv is a Ruby version management tool. Using this tool you can easily switch the version of Ruby on same system if installed multiple versions. By default Rbenv doesn’t handle installing Ruby versions so we also need to install ruby-build which is a tool that will help you to install specific version of Ruby which you need. Follow the instruction below to install Ruby using Rbenv:

At first, you should install dependencies for installation of 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

After that run the following curl command to install rbenv and ruby-build:

curl -sL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash -

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

Add $HOME/.rbenv/bin to the system PATH.

If you are using Bash, run:

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

If you are using Zsh run:

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

Select the latest and stable version of Ruby and you can set default version as per your need.

rbenv install 2.6.3
rbenv global 2.6.3

You can confirm installation by issuing below command:

ruby -v

It should show output as below:

Output
ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu]

Ruby Program Example#

We are going to create a simple ruby program. So create a demo.rb file using your favorite editor:

sudo nano demo.rb

Paste below lines in to that file:

puts "Ruby Simple Demo"

Save file and exit from editor using Ctrl+x.

To run demo.rb file issue below command:

ruby demo.rb

It will print simple output as below:

Output
Ruby Simple Demo

Conclusion#

You have successfully learned multiple ways to install Ruby on CentOS 7 system. If you have any problem or suggestion please leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Google Chrome on Debian 10 Buster
Next Article   How to List Installed Packages on Ubuntu

Related Posts

  • How to Install Php 8 on CentOS 8

    How to Install PHP 8 on CentOS 8

    January 27, 2021
  • How to Install Python 3.9 on CentOS 8

    How to Install Python 3.9 on CentOS 8

    December 31, 2020
  • How to Install GIMP 2.10 on CentOS 8

    How to Install GIMP 2.10 on CentOS 8

    December 30, 2020

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook