How to Install RubyGems on Ubuntu

How to Install RubyGems on Ubuntu

RubyGems is a Package Manager containing Gems. The Gem in Ruby is a piece of code or package that performs a specific functionality and also contains a bunch of utilities. Gem usually contains pre-coded information or data from someone else and it makes the process of understanding and using the methods of code easier.

This article discusses the installation procedure of RubyGems on Ubuntu.


You should have the following packages/tools installed:

  • Ubuntu 22.04 LTS Server
  • Root Access
  • “apt” Installed

How to Install RubyGems on Ubuntu?

The RubyGems Package Manager can be installed through the Ubuntu Terminal using the steps below.

Step 1: Update Existing Packages

Before installing RubyGems, ensure updating your existing Ubuntu Packages. Update your existing Ubuntu Packages using the command:

sudo apt update

Wait for the packages to update:

Upgrade the packages now using the command:

sudo apt upgrade

Step 2: Install RubyGems

RubyGems can be installed in Ubuntu using either the “apt” command to automatically download it from the official repository, or using the manual method by downloading the RubyGems Package first from the repository and then extracting the package. The following methods describe both the process.

Install using the “apt” Command

The “apt” command will download RubyGems from the official repository and install it once downloaded. Install RubyGems with the command:

sudo apt install ruby ruby-dev

It will ask for confirmation, press “Y” to continue with the installation process:

Install Manually using the “tgz” File

The RubyGems can also be installed manually by downloading the RubyGems “tgz” archive file and then extracting it with the “tar” Command. You can also install RubyGems by using the “wget” command:

wget https://rubygems.org/rubygems/rubygems-3.3.7.tgz

This will fetch the file and start downloading it:

Once the archive file downloads, extract it with the “tar” command:

tar xvf rubygems-3.3.7.tgz

Wait for the files to be extracted:

Once all the files are extracted, Navigate to the RubyGems directory using the “cd” Command:

cd rubygems-3.3.7/

Now List the files in the RubyGems Directory using “ls” command:


In the RubyGems Directory, look for the setup file “setup.rb”:

If the setup file exists, Install it using the command:

ruby setup.rb

This will install the RubyGems packages:

Step 3: Verify Installation

To verify, run the RubyGems Version Command on your Ubuntu System:

gem --version

The version once displayed verifies the installation of RubyGems. In our case, the version is “3.3.5”:

Step 4: Install a Package

Once the RubyGems Package Manager is installed, you can now use the “gem” command to install gems from the official RubyGems Community. To Install the “h2o” Gem Package, use the command:

sudo gem install h2o

The installation will be confirmed once the gem is added:

Step 5: Remove a Package

The installed gem packages can also be removed using the “remove” command with the “gem” command. Using the command below, remove the installed “h2o” gem package:

sudo gem uninstall h2o

The “h2o” gem package will be uninstalled:


The RubyGems can be installed from the official repository directly using the “apt” command or can be downloaded using the “wget” command and then extracted using the “tar” command. This article explained the “apt” and “wget” procedures to install RubyGems on Ubuntu.

Similar Posts