How To Install RubyGems On Linux

How to install RubyGems on Linux

RubyGems is a popular package manager for the Ruby programming language. RubyGems allows you to download and manage “gems”, or software packets, that you can use in your own Ruby programs. Many Ruby programs, like the Jekyll content management system are actually gems, and the plugins you can use for Jekyll are also gems. Installing RubyGems on your Linux server, or local workstation, can help you easily manage a vast library of gems.

How to Install RubyGems on Linux

There are a few different ways to install RubyGems on Linux. The path you choose will depend on your comfort level, which version you want, and other factors. You can install RubyGems from source or use some of the popular Linux package managers available for your distribution.

This article will cover the apt package manager available for Debian-based distributions like Ubuntu, as well as the yum package manager available for most RedHat-based Linux distributions such as CentOS and Fedora. This article also assumes that you have already installed a full version of Ruby in your system.

Using Package Managers

It is generally recommended that you not install RubyGems or subsequent gems as the root user. This is why the command below uses the sudo.

Using The apt Package Manager (Debian, Ubuntu)

To install RubyGems with the apt package manager, you can use the following command:

sudo apt install rubygems

Using The yum Package Manager (CentOS, Fedora)

To install RubyGems with the yum package manager, you can use the following command:

sudo yum install rubygems

Installing RubyGems From Source

Installing RubyGems from source is a little more complicated than the above options. So why install from source?

Sometimes, the software versions available in package manager repositories are not the latest and greatest but rather a more stable, earlier version. This is fine for most day-to-day usage of package managers, but can create problems if you require the absolute latest and greatest packages. In those instances, installing from source, where possible, is the best option.

To install RubyGems from source, you will need to download a copy of the latest source code from the RubyGems website.

The following commands use wget to download the RubyGems source code package. However, this is not required. You can download the package archive in any style you prefer as long as you can access it easily on the command line. If you would like to use wget, you will want to make sure it is installed on your system.

From the RubyGems website, select which format you want to download the package as (.zip, tarball, or otherwise). For usage with wget you only need the live download link for the “TGZ” format, which you can copy from your web browser.

Once you have the link for the package, you can proceed to use wget to download the package to the desired location. Many users prefer to download package archives to the /tmp directory, because they will be automatically trashed by the operating system on reboot:

cd /tmp

To the proceed with the download (bear in mind your version may be different):


Now, you can open the archive with the tar command:

tar xvf rubygems-3.3.7

Change into the new directory:

cd rubygems-3.3.7/

Complete the installation by running the installation command:

ruby setup.rb

That’s it! You now know how to install RubyGems in your Linux server or desktop environment. If you have any questions or comments feel free to drop them below:

Christopher Maiorana Content Writer II

Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.

More Articles by Christopher

2 thoughts on “How To Install RubyGems On Linux

  1. Everything worked except ruby setup.rb. Get the following error:
    /tmp/rubygems-3.3.7/lib/rubygems/compatibility.rb:16:in `’: undefined method `deprecate_constant’ for Gem:Module (NoMethodError)
    from /tmp/rubygems-3.3.7/lib/rubygems/compatibility.rb:14:in `’
    from /tmp/rubygems-3.3.7/lib/rubygems.rb:15:in `require_relative’
    from /tmp/rubygems-3.3.7/lib/rubygems.rb:15:in `’
    from setup.rb:22:in `require’
    from setup.rb:22:in `’

Was this article helpful? Join the conversation!

Leap into Savings
Leap Ahead with Limited Time Deals