How to install Ruby on CentOS/Red Hat 7 with Easy Steps

In this article, I will take you through the steps to install ruby on CentOS/RedHat 7.Ruby is an interpreted, high-level, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro “Matz” Matsumoto in Japan.
Ruby is dynamically typed and uses garbage collection. It supports multiple programming paradigms, including procedural, object-oriented, and functional programming. According to the creator, Ruby was influenced by Perl, Smalltalk, Eiffel, Ada, Basic, and Lisp.

Install Ruby on CentOS/RedHat 7

Step 1 – Prerequisites

You need to have a running RedHat/CentOS System with yum tool installed before you start the steps to Install ruby on CentOS.

How to install Ruby on CentOS/Red Hat 7 with Easy Steps 1

Step 2 – Update the System 

Firstly you need to update your system using yum update command.

[root@localhost ~]# yum update
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/2): extras/7/x86_64/primary_db | 153 kB 00:00
(2/2): updates/7/x86_64/primary_db | 2.8 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package binutils.x86_64 0:2.27-41.base.el7 will be updated
---> Package binutils.x86_64 0:2.27-41.base.el7_7.1 will be an update
---> Package device-mapper.x86_64 7:1.02.158-2.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.158-2.el7_7.2 will be an update
---> Package device-mapper-event.x86_64 7:1.02.158-2.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.158-2.el7_7.2 will be an update
---> Package device-mapper-event-libs.x86_64 7:1.02.158-2.el7 will be updated
---> Package device-mapper-event-libs.x86_64 7:1.02.158-2.el7_7.2 will be an upd ate
---> Package device-mapper-libs.x86_64 7:1.02.158-2.el7 will be updated
---> Package device-mapper-libs.x86_64 7:1.02.158-2.el7_7.2 will be an update
---> Package firewalld.noarch 0:0.6.3-2.el7_7.1 will be updated
---> Package firewalld.noarch 0:0.6.3-2.el7_7.2 will be an update
---> Package firewalld-filesystem.noarch 0:0.6.3-2.el7_7.1 will be updated
---> Package firewalld-filesystem.noarch 0:0.6.3-2.el7_7.2 will be an update
---> Package hostname.x86_64 0:3.13-3.el7 will be updated
---> Package hostname.x86_64 0:3.13-3.el7_7.1 will be an update
---> Package kernel.x86_64 0:3.10.0-1062.4.1.el7 will be installed
---> Package kernel-tools.x86_64 0:3.10.0-1062.1.2.el7 will be updated
---> Package kernel-tools.x86_64 0:3.10.0-1062.4.1.el7 will be an update
...........................................................................

Step 3 – Install Ruby through yum

Now install ruby on centos through command yum install ruby as shown below.

[root@localhost ~]# yum install ruby -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
Resolving Dependencies
--> Running transaction check
---> Package ruby.x86_64 0:2.0.0.648-36.el7 will be installed
--> Processing Dependency: ruby-libs(x86-64) = 2.0.0.648-36.el7 for package: ruby-2.0.0.648-36.el7.x86_64
--> Processing Dependency: rubygem(bigdecimal) >= 1.2.0 for package: ruby-2.0.0.648-36.el7.x86_64
--> Processing Dependency: ruby(rubygems) >= 2.0.14.1 for package: ruby-2.0.0.648-36.el7.x86_64
--> Processing Dependency: libruby.so.2.0()(64bit) for package: ruby-2.0.0.648-36.el7.x86_64
--> Running transaction check
---> Package ruby-libs.x86_64 0:2.0.0.648-36.el7 will be installed
..............................................................................

Step 4 – Check Ruby Version

Once installation is completed, Check the installed Ruby Version through ruby –version command.

[root@localhost ~]# ruby --version
ruby 2.0.0p648 (2015-12-16) [x86_64-linux]

Step 5 – Write Your First Ruby Program

After successfully installing ruby in your system, you can now write your first Ruby Program.

[root@localhost ~]# cat hello.rb
puts "Hello World!!"

Output:-

Advertisements
[root@localhost ~]# ruby hello.rb
Hello World!!

Congratulations!!! You have written and executed your first Ruby Program.

Also Read: Difference between Ruby Blocks and Procs

Reference: Ruby Documentation

Advertisements

Leave a Reply