RubyGems Is Already Installed: Here’s How to Check

ubuntu install rubygems

Run gem -v. If that prints a version number, RubyGems is already installed — it ships inside Ruby itself and has since Ruby 1.9, so there is no separate “install RubyGems” step for any Ruby you’d install today. RubyGems’ own guide states it plainly: “RubyGems ships with Ruby, so the gem command is available as soon as Ruby is installed.” The old version of this page’s “Step 4: Install RubyGems Manually” — downloading a tarball and running sudo ruby setup.rb — describes a workaround for Ruby versions from over a decade ago, not a step a current install needs.

Verified on this machine

$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin25]

$ gem -v
3.0.3.1

No install step ran between those two commands. RubyGems 3.0.3.1 was already there because it shipped with this Ruby 2.6.10. That’s macOS’s system Ruby, not Ubuntu’s — but the mechanism (RubyGems bundled inside the Ruby distribution itself) is the same across platforms; only the package name that installs Ruby differs.

What actually differs on Ubuntu — cited, not run

There is no Ubuntu machine available to this rewrite, so the following is cited to Ubuntu’s own package pages, not observed. On Ubuntu 24.04 (noble), the ruby-full package page shows it installs Ruby 3.2 (package version 1:3.2~ubuntu1). Ruby’s own site lists the current stable release as 4.0.6 — checked today. That’s a two-major-version gap between what apt install ruby-full gives you and what’s current upstream, which is the real reason someone reaches for a version manager (rbenv, RVM, or similar) instead of the distro package: not because the distro Ruby lacks RubyGems, but because it’s older than upstream by design — Ubuntu freezes package versions at release and only backports security fixes. If you need a specific recent Ruby (for a gem that requires it, or to match a deployment target), a version manager gets you there; the distro package is for running Ruby scripts other Ubuntu packages depend on.

Why sudo gem install is worth avoiding

On this machine, the default (system) gem directory is not writable without root — confirmed directly:

$ gem environment gemdir
/Library/Ruby/Gems/2.6.0

$ touch /Library/Ruby/Gems/2.6.0/probe
touch: /Library/Ruby/Gems/2.6.0/probe: Permission denied

$ gem environment | grep 'USER INSTALLATION'
USER INSTALLATION DIRECTORY: /Users/[username redacted]/.gem/ruby/2.6.0
# this directory IS writable without sudo — confirmed by touch, then removed
# (only the account name in the line above is redacted; on Ubuntu the same
#  path is /home/<your-user>/.gem/ruby/<version>)

That’s macOS’s System Integrity Protection specifically, but the underlying shape of the problem is general: a system Ruby’s gem directory is something the OS’s own package manager considers part of its territory. On Debian and Ubuntu, ruby-full is a dpkg-tracked package, and files that gem install (run as root) drops into the same tree aren’t tracked by dpkg — so removing or upgrading the Ruby package later can leave orphaned gem files behind, or conflict with files the package manager expects to own. RubyGems supports a per-user install path precisely to route around this: add gem: --user-install to ~/.gemrc, or pass --user-install per command, and installs go to a directory in your home folder that needs no sudo and touches nothing the package manager tracks. A page that teaches sudo gem install as the default is teaching a habit that fights your package manager later, not one that saves a step now.

If gem -v genuinely fails

On Ubuntu, that means Ruby itself isn’t installed — install it with sudo apt install ruby-full (cited: packages.ubuntu.com), which pulls in RubyGems as part of the same package. There’s no separate RubyGems package to reach for. If you already have Ruby but a native-extension gem fails to build afterward, that’s a different, more common failure — see what to do when a gem’s extconf.rb fails.

/verify/how-to-install-rubygems-ubuntu.sh checks that gem -v and ruby -v run on your machine, confirms RubyGems’ reported version is bundled (not separately installed), and checks whether your system gem directory is writable without sudo — reporting SKIP for anything Ubuntu-specific if you’re not on Ubuntu.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.