Cyberithub

How to Install RubyGems on Linux Using 7 Easy Steps

Advertisements

In this article, I will take you through the steps to install RubyGems on Linux Using 7 Easy Steps. RubyGems is a free and open source package manager framework for ruby. A package (also known as a library) contains a set of functionality that can be invoked by a Ruby program, such as reading and parsing an XML file. We call these packages "gems" and RubyGems is a tool to install, create, manage and load these packages in your Ruby environment. RubyGems is also a client for RubyGems.org, a public repository of Gems that allows you to publish a Gem that can be shared and used by other developers.

How to Install RubyGems on Linux Using 7 Easy Steps

How to Install RubyGems on Linux Using 7 Easy Steps

Also Read: How to Install Terraspace on Linux Using 6 Easy Steps

Step 1: Prerequisites

a) You should have a running Linux(it is Ubuntu 20.04 LTS in our case) Server.

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

c) You should have a package manager available in your System.

 

Step 2: Update Your Server

In the first step, you need to update your package cache with all the latest available versions from Ubuntu repo by using sudo apt update command as shown below. If any of the packages needs to be upgraded then you can upgrade it by using sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update
[sudo] password for cyberithub:
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:4 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Hit:7 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Fetched 336 kB in 3s (126 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done

If you are using RHEL/CentOS based systems then you can use sudo dnf update or sudo yum update command as shown below.

[cyberithub@centos8 ~]$ sudo dnf update
[sudo] password for cyberithub:
Last metadata expiration check: 0:22:56 ago on Sun 18 Sep 2022 02:50:07 PM EDT.
Dependencies resolved.
Nothing to do.
Complete!

 

Step 3: Install RubyGems

There are multiple ways to install RubyGems on a Linux system. You can choose any of the below method depending on the Linux distribution you are currently using.

a) On Ubuntu/Debian

If you are using Ubuntu/Debian based systems then to install RubyGems package you need to use sudo apt install ruby ruby-dev command as shown below.

cyberithub@ubuntu:~$ sudo apt install ruby ruby-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libgmp-dev libgmpxx4ldbl libruby2.7 rake ruby2.7 ruby2.7-dev ruby2.7-doc
Suggested packages:
gmp-doc libgmp10-doc libmpfr-dev ri
The following NEW packages will be installed:
libgmp-dev libgmpxx4ldbl libruby2.7 rake ruby ruby-dev ruby2.7 ruby2.7-dev ruby2.7-doc
0 upgraded, 9 newly installed, 0 to remove and 1 not upgraded.
Need to get 2,676 kB/6,372 kB of archives.
After this operation, 43.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libgmpxx4ldbl amd64 2:6.2.0+dfsg-4 [9,128 B]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libgmp-dev amd64 2:6.2.0+dfsg-4 [320 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 ruby2.7-dev amd64 2.7.0-5ubuntu1.7 [182 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu focal/main amd64 ruby-dev amd64 1:2.7+1 [4,632 B]
Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 ruby2.7-doc all 2.7.0-5ubuntu1.7 [2,160 kB]
Fetched 2,676 kB in 2s (1,156 kB/s)
Selecting previously unselected package libgmpxx4ldbl:amd64.
(Reading database ... 230710 files and directories currently installed.)
Preparing to unpack .../0-libgmpxx4ldbl_2%3a6.2.0+dfsg-4_amd64.deb ...
Unpacking libgmpxx4ldbl:amd64 (2:6.2.0+dfsg-4) ...
Selecting previously unselected package libgmp-dev:amd64.
Preparing to unpack .../1-libgmp-dev_2%3a6.2.0+dfsg-4_amd64.deb ...
Unpacking libgmp-dev:amd64 (2:6.2.0+dfsg-4) ...
Selecting previously unselected package ruby2.7.
Preparing to unpack .../2-ruby2.7_2.7.0-5ubuntu1.7_amd64.deb ...
...................................................

b) On RHEL/CentOS

If you are using RHEL/CentOS based systems then to install RubyGems package you need to use sudo dnf install ruby command as shown below. If you are having yum utility then use sudo yum install ruby command.

[cyberithub@centos8 ~]$ sudo dnf install ruby
Last metadata expiration check: 0:01:25 ago on Sun 18 Sep 2022 02:39:39 PM EDT.
Dependencies resolved.
=============================================================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================================================
Installing:
ruby x86_64 2.5.9-107.module_el8.4.0+847+ee687b6c appstream 87 k
Installing dependencies:
ruby-irb noarch 2.5.9-107.module_el8.4.0+847+ee687b6c appstream 102 k
ruby-libs x86_64 2.5.9-107.module_el8.4.0+847+ee687b6c appstream 2.9 M
rubygem-json x86_64 2.1.0-107.module_el8.4.0+847+ee687b6c appstream 91 k
rubygem-psych x86_64 3.0.2-107.module_el8.4.0+847+ee687b6c appstream 95 k
Installing weak dependencies:
rubygem-bigdecimal x86_64 1.3.4-107.module_el8.4.0+847+ee687b6c appstream 97 k
rubygem-did_you_mean noarch 1.2.0-107.module_el8.4.0+847+ee687b6c appstream 81 k
rubygem-io-console x86_64 0.4.6-107.module_el8.4.0+847+ee687b6c appstream 67 k
rubygem-openssl x86_64 2.1.2-107.module_el8.4.0+847+ee687b6c appstream 189 k
rubygem-rdoc noarch 6.0.1.1-107.module_el8.4.0+847+ee687b6c appstream 456 k
rubygems noarch 2.7.6.3-107.module_el8.4.0+847+ee687b6c appstream 308 k

Transaction Summary
=============================================================================================================================================================
Install 11 Packages

Total download size: 4.5 M
Installed size: 14 M
Is this ok [y/N]: y
........................................

 

Step 4: Check Version

If you want to check RubyGems utility version then you need to use gem --version command as shown below.

cyberithub@ubuntu:~$ gem --version
3.1.2

 

Step 5: Install a Package

If you want to install a package let's say terraspace using gem utility then you need to use sudo gem install terraspace command as shown below.

cyberithub@ubuntu:~$ sudo gem install terraspace
Building native extensions. This could take a while...
Successfully installed eventmachine-1.2.7
Successfully installed eventmachine-tail-0.6.5
Successfully installed graph-2.10.0
Successfully installed rhcl-0.1.0
Successfully installed hcl_parser-0.2.2
Successfully installed tilt-2.0.11
Successfully installed render_me_pretty-0.8.4
Successfully installed jmespath-1.6.1
Successfully installed aws-partitions-1.631.0
Successfully installed aws-eventstream-1.2.0
Successfully installed aws-sigv4-1.5.1
Successfully installed aws-sdk-core-3.149.0
Successfully installed aws-sdk-kms-1.58.0
Successfully installed aws-sdk-s3-1.114.0
Successfully installed nokogiri-1.13.8-x86_64-linux
RubyZip 3.0 is coming!
**********************

The public API of some Rubyzip classes has been modernized to use named
parameters for optional arguments. Please check your usage of the
following classes:
* `Zip::File`
* `Zip::Entry`
* `Zip::InputStream`
* `Zip::OutputStream`

Please ensure that your Gemfiles and .gemspecs are suitably restrictive
to avoid an unexpected breakage when 3.0 is released (e.g. ~> 2.3.0).
See https://github.com/rubyzip/rubyzip for details. The Changelog also
lists other enhancements and bugfixes that have been implemented since
version 2.3.0.
...............................................

 

Step 6: Remove a Package

If you want to remove a package let's say terraspace using gem utility then you need to use sudo gem uninstall terraspace command as shown below.

cyberithub@ubuntu:~$ sudo gem uninstall terraspace
Remove executables:
terraspace

in addition to the gem? [Yn] Y
Removing terraspace
Successfully uninstalled terraspace-2.2.2

 

Step 7: Check all the available options

If you want to check all the options available with gem command then you need to use gem --help command as shown below.

cyberithub@ubuntu:~$ gem --help
RubyGems is a sophisticated package manager for Ruby. This is a
basic help message containing pointers to more information.

Usage:
gem -h/--help
gem -v/--version
gem command [arguments...] [options...]

Examples:
gem install rake
gem list --local
gem build package.gemspec
gem help install

Further help:
gem help commands list all 'gem' commands
gem help examples show some examples of usage
gem help gem_dependencies gem dependencies file guide
gem help platforms gem platforms guide
gem help <COMMAND> show help on COMMAND
(e.g. 'gem help install')
gem server present a web page at
http://localhost:8808/
with info about installed gems
Further information:
http://guides.rubygems.org

Leave a Comment