How To Install RubyGems on Ubuntu

By Chandrashekhar Fakirpure

Updated on Feb 02, 2024

In this tutorial, we will show the steps to install RubyGems on Ubuntu 22.04.

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries. RubyGems is hosted by the Ruby community and it makes the installation of Gems simple on the system.

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.

The RubyGems software allows you to easily download, install, and use ruby software packages on your system. The software package is called a “gem” which contains a packaged Ruby application or library.

We have covered installation of RubyGems on Ubuntu 22.04 using source code.

Prerequisites

  • A Ubuntu 22.04 installed dedicated server or KVM VPS.
  • A root user access or normal user with sudo privileges.

Step 1 - Update The Server

Keep the server up to date. Use following command to update the Ubuntu server.

apt update

Step 2 - Install Ruby

Here, we will install Ruby and once we download source code, we will use Ruby to setup/update Gems.

apt install ruby -y

Step 3 - Download And Extract RubyGems

Use following command to download RubyGems in TGZ file format.

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

Extract it using tar command.

tar xvzf rubygems-3.4.8.tgz

Step 4 - Setup RubyGems

Change current working directory.

cd rubygems-3.4.8

Use following command to setup latest version on RubyGems:

ruby setup.rb

Verify the installation.

gem -v

Output:

3.4.8

Here are the some useful commands of RubyGems

GEM BUILD

Build a gem from a gemspec.

gem build GEMSPEC_FILE [options]

GEM CHECK

Check a gem repository for added or missing files.

gem check [OPTIONS] [GEMNAME ...] [options]

GEM EXEC

Run a command from a gem

gem exec [options --] COMMAND [args] [options]

GEM INSTALL

Install a gem into the local repository.

gem install [options] GEMNAME [GEMNAME ...] -- --build-flags [options]

To know more about the commands, here is the official documentation for reference commands.

We have seen, how to install RubyGems on Ubuntu 22.04. Here is the RubyGems official Documentation.