Cyberithub

How to Install Ruby on Ubuntu 22.04 LTS (Jammy Jellyfish)

Advertisements

In this article, we will see how to install ruby on Ubuntu 22.04 LTS (Jammy Jellyfish). Ruby is a free, dynamic and open source programming language. It is great for building web and desktop based applications. Ruby was first publicly released worldwide in the year 1995. Since then it has drawn massive attention of developers due to its focus on simplicity and productivity. Ruby is an object oriented language but unlike other languages it features single inheritance only.

Due to its flexibility, it allows developers to alter its parts. Ruby is known to be more powerful than Perl and more object oriented than Python. More on official website. It is also very easy to install and use in almost all the famous platforms. Here we will see the steps to install and use ruby on Ubuntu 22.04 LTS based systems.

 

How to Install Ruby on Ubuntu 22.04 LTS (Jammy Jellyfish)

How to Install Ruby on Ubuntu 22.04 LTS (Jammy Jellyfish)

Also Read: How to Install libssl-dev package on Ubuntu 22.04 LTS (Jammy Jellyfish)

Step 1: Prerequisites

a) You should have a running Ubuntu 22.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or snap utility available in your Server.

 

Step 2: Update Your Server

In the first step, you might want to check and install all the available updates from default Ubuntu repo by using sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Hit:1 https://artifacts.elastic.co/packages/8.x/apt stable InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:5 https://dl.google.com/linux/chrome/deb stable InRelease [1,825 B]
Get:6 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [108 kB]
Get:7 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,061 B]
Get:8 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 DEP-11 Metadata [99.8 kB]
Get:9 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [41.4 kB]
Get:10 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [22.0 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 DEP-11 Metadata [274 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:13 http://in.archive.ubuntu.com/ubuntu jammy-backports/main amd64 DEP-11 Metadata [7,976 B]
Get:14 http://in.archive.ubuntu.com/ubuntu jammy-backports/universe amd64 DEP-11 Metadata [15.4 kB]
Fetched 802 kB in 7s (118 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
#
# An OpenSSL vulnerability has recently been fixed with USN-6188-1 & 6119-1:
# CVE-2023-2650: possible DoS translating ASN.1 object identifiers.
# Ensure you have updated the package to its latest version.
#
The following packages have been kept back:
gjs libgjs0g
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

 

Step 3: Install Ruby

In the next step, you can install ruby in your system using any of the below methods depending on your requirement and tools availability.

a) Using APT

If you want to install ruby from default Ubuntu repo then you need to use sudo apt install ruby command as shown below. This will download and install the package along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt install ruby
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
fonts-lato javascript-common libjs-jquery libruby3.0 rake ruby-net-telnet ruby-rubygems ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration
Suggested packages:
apache2 | lighttpd | httpd ri ruby-dev bundler
The following NEW packages will be installed:
fonts-lato javascript-common libjs-jquery libruby3.0 rake ruby ruby-net-telnet ruby-rubygems ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration
0 upgraded, 12 newly installed, 0 to remove and 2 not upgraded.
Need to get 8,575 kB of archives.
After this operation, 37.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 fonts-lato all 2.0-2.1 [2,696 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 javascript-common all 11+nmu1 [5,936 B]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libjs-jquery all 3.6.0+dfsg+~3.5.13-1 [321 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 rubygems-integration all 1.18 [5,336 B]
Get:5 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 ruby3.0 amd64 3.0.2-7ubuntu2.4 [50.1 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 ruby-rubygems all 3.3.5-2 [228 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 ruby amd64 1:3.0~exp1 [5,100 B]
Get:8 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 rake all 13.0.6-2 [61.7 kB]
Get:9 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 ruby-net-telnet all 0.1.1-2 [12.6 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 ruby-webrick all 1.7.0-3 [51.8 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 ruby-xmlrpc all 0.3.2-1ubuntu0.1 [24.9 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libruby3.0 amd64 3.0.2-7ubuntu2.4 [5,113 kB]
Fetched 8,575 kB in 5s (1,600 kB/s)
............................................................

b) Using Snap

Second method that you can think of using is to install ruby as a snap package. If you have snap utility available in your system then you can easily install ruby from snap store by using sudo snap install ruby --classic command as shown below.

cyberithub@ubuntu:~$ sudo snap install ruby --classic
ruby 3.2.2 from Ruby core team (rubylang**) installed

 

Step 4: Check Version

If you install ruby from default Ubuntu repo then you might get different version. For example, when I installed from default Ubuntu repo then I received version 3.0.2.

cyberithub@ubuntu:~$ ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux-gnu]

But if you install as snap package then you might get another version. For example, when I installed as snap package then I got version 3.2.2.

cyberithub@ubuntu:~$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

 

Step 5: Using Ruby

Now that ruby is installed, it is time to write a sample program to test the utility. Here we are writing a simple program to display "Hi, This is from CyberITHub !!" on the output.

cyberithub@ubuntu:~$ nano hello.rb
puts "Hi, This is from CyberITHub !!"

To run above ruby program, you need to use ruby hello.rb command. It should display "Hi, This is from CyberITHub !!" on the output as shown below.

cyberithub@ubuntu:~$ ruby hello.rb
Hi, This is from CyberITHub !!

 

Step 6: Uninstall Ruby

Once you are done using ruby, you can choose to uninstall it from the system by using any of the below methods depending on how you have installed it.

a) Using APT

If you installed it from default Ubuntu repo then to uninstall you need to use sudo apt remove ruby command as shown below. But you need to be careful as you might notice it is removing other ruby packages as well. So you need to be very sure before running below command otherwise sometimes it may cause irreparable losses in your System.

cyberithub@ubuntu:~$ sudo apt remove ruby
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
fonts-lato javascript-common libjs-jquery ruby-net-telnet ruby-webrick ruby-xmlrpc rubygems-integration
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
libruby3.0 rake ruby ruby-rubygems ruby3.0
0 upgraded, 0 newly installed, 5 to remove and 2 not upgraded.
After this operation, 24.6 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 232094 files and directories currently installed.)
Removing ruby-rubygems (3.3.5-2) ...
Removing ruby (1:3.0~exp1) ...
Removing ruby3.0 (3.0.2-7ubuntu2.4) ...
Removing libruby3.0:amd64 (3.0.2-7ubuntu2.4) ...
Removing rake (13.0.6-2) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

b) Using Snap

If you installed as snap package from Snap store then to uninstall you need to use sudo snap remove ruby command as shown below.

cyberithub@ubuntu:~$ sudo snap remove ruby
[sudo] password for cyberithub:
ruby removed

Leave a Comment