Cyberithub

How to Install Ruby on Ubuntu 18.04 with Easy Steps

In this article, I will take you through the steps to install Ruby on Ubuntu 18.04. 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.

Install Ruby on Ubuntu

Below are the steps to install Ruby on Ubuntu 18.04.

Step 1: Prerequisites

You need to have a running Ubuntu System and you have sudo access to run the steps.

How to Install Ruby on Ubuntu 18.04 with Easy Steps 1

Step 2: Update the System

First you need update your system using apt-get update command.

root@test-ubuntu:~# apt-get update
Hit:1 http://ppa.launchpad.net/ansible/ansible/ubuntu bionic InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [625 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [816 kB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [38.5 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 48x48 Icons [17.6 kB]
Get:10 http://security.ubuntu.com/ubuntu bionic-security/main DEP-11 64x64 Icons [41.5 kB]
Get:11 http://security.ubuntu.com/ubuntu bionic-security/universe i386 Packages [601 kB]
Get:12 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [627 kB]
Get:13 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [210 kB]

.............................................................................................................................................................................

Step 3: Install Ruby

Now you can install ruby through apt-get install ruby command.

root@test-ubuntu:~# apt-get install ruby
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dh-python libpython3-dev libpython3.6-dev python3-dev python3-wheel python3.6-dev
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
fonts-lato libruby2.5 rake ruby-did-you-mean ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.5 rubygems-integration
Suggested packages:
ri ruby-dev bundler
The following NEW packages will be installed:
fonts-lato libruby2.5 rake ruby ruby-did-you-mean ruby-minitest ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.5 rubygems-integration
0 upgraded, 11 newly installed, 0 to remove and 216 not upgraded.
Need to get 6,001 kB of archives.
After this operation, 27.2 MB of additional disk space will be used.

...........................................................................................................................................................................

Step 4: Check Ruby version

Once ruby is installed successfully, you can check the ruby version.

root@test-ubuntu:~# ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]

Step 5: Write Your First Ruby Program

Congratulations You have successfully installed ruby in your system. Let’s write your first Ruby Program.

root@test-ubuntu:~# cat hello.rb
puts "Hello World!!"

Output:-

root@test-ubuntu:~# ruby hello.rb
Hello World!!

Also Read: How to install Ruby on RedHat/CentOS 7
Reference: Ruby Documentation

Leave a Comment