AMP AMP

How To Install Ruby And Execute Ruby Script On Rocky Linux 8.6

To Install Ruby And Execute Ruby Script On Rocky Linux 8.6

Introduction

Ruby is a powerful scripting language. Scripts can be used to automate tasks including creating and searching files and managing and organizing subdirectories. Ruby scripting language is used by many companies like Github, Chef, and Puppet. DevOps teams use scripting for the purpose of combining development and operations.

Step 1 : Check the installed version of OS by using the below command

[root@linuxhelp ~]#cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"

Step 2 : Check ruby installed or not by using rpm command

[root@linuxhelp ~]# rpm -qa |grep ruby

Step 3: Install ruby by using the below command

[root@linuxhelp ~]# yum install ruby*
Last metadata expiration check: 1:57:33 ago on Fri 15 Jul 2022 05:52:49 PM EDT.
Dependencies resolved.
====================================================================================================
 Package                     Arch    Version                                       Repository  Size
====================================================================================================
Installing:
 ruby                        x86_64  2.5.9-109.module+el8.5.0+740+b85cbe0d         appstream   86 k
 ruby-devel                  x86_64  2.5.9-109.module+el8.5.0+740+b85cbe0d         appstream  125 k
 ruby-doc                    noarch  2.5.9-109.module+el8.5.0+740+b85cbe0d         appstream  5.3 M
 ruby-hivex                  x86_64  1.3.18-23.module+el8.6.0+847+b490afdd         appstream  219 k
 ruby-irb                    noarch  2.5.9-109.module+el8.5.0+740+b85cbe0d         appstream  101 k
 ruby-libguestfs             x86_64  1:1.44.0-5.module+el8.6.0+847+b490afdd.rocky  appstream  286 k
 ruby-libs                   x86_64  2.5.9-109.module+el8.5.0+740+b85cbe0d         appstream  2.9 M
 rubygem-abrt                noarch  0.3.0-4.module+el8.5.0+739+43897a5e           appstream   13 k
 rubygem-abrt-doc            noarch  0.3.0-4.module+el8.5.0+739+43897a5e           appstream  198 k
 rubygem-bigdecimal          x86_64  1.3.4-109.module+el8.5.0+740+b85cbe0d         appstream   97 k
 rubygem-bson                x86_64  4.3.0-2.module+el8.4.0+592+03ff458a           appstream   53 k
 rubygem-bson-doc            noarch  4.3.0-2.module+el8.4.0+592+03ff458a           appstream  374 k
 rubygem-bundler             noarch  1.16.1-4.module+el8.5.0+739+43897a5e          appstream  352 k
 appstream  768 k
 libguestfs-appliance        x86_64  1:1.44.0-5.module+el8.6.0+847+b490afdd.rocky  appstream  2.1 M
 libpq                       x86_64  13.5-1.el8                                    appstream  197 k
 mariadb-connector-c         x86_64  3.1.11-2.el8_3                                appstream  199 k
 mariadb-connector-c-config  noarch  3.1.11-2.el8_3                                appstream   14 k
 scrub                       x86_64  2.5.2-16.el8                                  appstream   43 k
 supermin                    x86_64  5.2.1-1.module+el8.6.0+847+b490afdd           appstream  712 k
 syslinux                    x86_64  6.04-5.el8                                    baseos     577 k
 syslinux-extlinux           x86_64  6.04-5.el8                                    baseos     140 k
 syslinux-extlinux-nonlinux  noarch  6.04-5.el8                                    baseos     385 k
 syslinux-nonlinux           noarch  6.04-5.el8                                    baseos     551 k

Transaction Summary
====================================================================================================
Install  46 Packages

Total download size: 21 M
Installed size: 69 M
Is this ok [y/N]: y
Downloading Packages:
(1/46): hivex-1.3.18-23.module+el8.6.0+847+b490afdd.x86_64.rpm      143 kB/s | 112 kB     00:00    
(2/46): libguestfs-1.44.0-5.module+el8.6.0+847+b490afdd.rocky.x86_6 905 kB/s | 768 kB     00:00    
(3/46): libguestfs-appliance-1.44.0-5.module+el8.6.0+847+b490afdd.r 2.1 MB/s | 2.1 MB     00:00    
(4/46): libpq-13.5-1.el8.x86_64.rpm                                 797 kB/s | 197 kB     00:00    
(5/46): mariadb-connector-c-config-3.1.11-2.el8_3.noarch.rpm        122 kB/s |  14 kB     00:00    
(6/46): mariadb-connector-c-3.1.11-2.el8_3.x86_64.rpm               634 kB/s | 199 kB     00:00    
(7/46): ruby-2.5.9-109.module+el8.5.0+740+b85cbe0d.x86_64.rpm       348 kB/s |  86 kB     00:00    
(8/46): ruby-devel-2.5.9-109.module+el8.5.0+740+b85cbe0d.x86_64.rpm 698 kB/s | 125 kB     00:00    
(45/46): syslinux-6.04-5.el8.x86_64.rpm                             658 kB/s | 577 kB     00:00    
(46/46): syslinux-nonlinux-6.04-5.el8.noarch.rpm                    1.2 MB/s | 551 kB     00:00    
----------------------------------------------------------------------------------------------------
Total                                                               3.0 MB/s |  21 MB     00:07     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                            1/1 
  Installing       : ruby-libs-2.5.9-109.module+el8.5.0+740+b85cbe0d.x86_64                    1/46 
  Installing       : ruby-irb-2.5.9-109.module+el8.5.0+740+b85cbe0d.noarch                     2/46 
  Installing       : rubygem-bigdecimal-1.3.4-109.module+el8.5.0+740+b85cbe0d.x86_64           3/46 
  Installing       : rubygem-did_you_mean-1.2.0-109.module+el8.5.0+740+b85cbe0d.noarch         4/46 
  Installing       : rubygem-io-console-0.4.6-109.module+el8.5.0+740+b85cbe0d.x86_64           5/46 
  Installing       : rubygem-json-2.1.0-109.module+el8.5.0+740+b85cbe0d.x86_64                 6/46 
  Installing       : rubygem-openssl-2.1.2-109.module+el8.5.0+740+b85cbe0d.x86_64              7/46 
  Installing       : rubygem-psych-3.0.2-109.module+el8.5.0+740+b85cbe0d.x86_64                8/46 
  Installing       : rubygem-rdoc-6.0.1.1-109.module+el8.5.0+740+b85cbe0d.noarch               9/46 
  Installing       : rubygems-2.7.6.3-109.module+el8.5.0+740+b85cbe0d.noarch                  10/46 
  Installing       : ruby-2.5.9-109.module+el8.5.0+740+b85cbe0d.x86_64                        11/46 
  Installing       : syslinux-nonlinux-6.04-5.el8.noarch                                      12/46 
  Installing       : syslinux-6.04-5.el8.x86_64                                               13/46 
  Installing       : hivex-1.3.18-23.module+el8.6.0+847+b490afdd.x86_64                       14/46 
  Installing       : rubygem-bson-4.3.0-2.module+el8.4.0+592+03ff458a.x86_64                  15/46 
  Installing       : rubygem-mongo-2.5.1-2.module+el8.4.0+592+03ff458a.noarch                 16/46 
  Installing       : syslinux-extlinux-nonlinux-6.04-5.el8.noarch                             17/46 
  Installing       : syslinux-extlinux-6.04-5.el8.x86_64                                      18/46 
  Running scriptlet: syslinux-extlinux-6.04-5.el8.x86_64                                      18/46 
  Installing       : rubygem-bundler-1.16.1-4.module+el8.5.0+739+43897a5e.noarch              19/46 
  Installing       : rubygem-abrt-0.3.0-4.module+el8.5.0+739+43897a5e.noarch                  20/46 
  Installing       : rubygem-power_assert-1.1.1-109.module+el8.5.0+740+b85cbe0d.noarch        21/46 

Step 4 : Check the installed version of ruby by using the below command

[root@linuxhelp ~]# ruby --version
ruby 2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]

Step 5 Create the .rb file to enter ruby script by using the below command

[root@linuxhelp ~]# vim sample.rb
#!/usr/bin/env ruby

puts 'what is your name?'
name = gets.chomp
puts "Hello #{name}!"

Step 6 : run the ruby script by using the below command

[root@linuxhelp ~]# ruby sample.rb 
what is your name?
Mohamed
Hello Mohamed!

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Install And Execute Ruby Script On Rocky Linux 8.6 . Your feedback is much welcome.

FAQ
Q
Name some data types in Ruby?
A
Numbers
Strings
Symbols
Hashes
Arrays
Booleans
Q
What are Ruby variables?
A
Local variable
Class variable
Instance variable
Global variable
Q
Name some operators used in Ruby?
A
Unary operator
Airthmetic operator
Bitwise operator
Logical operator
Ternary operator
Q
List some features of Ruby?
A
Object-oriented
Flexible
Dynamic typing and Duck typing
Garbage collector
Keyword arguments
Q
Who is the developer of Ruby?
A
Ruby is designed and developed by Yukihiro "Martz" Matsumoto in mid-1990 in Japan.