Before checking the version, ensure RubyGems is installed by running:
which gem
This should return the path to your gem executable, typically something like /usr/bin/gem
or /home/username/.rbenv/shims/gem
.
The standard command to check your RubyGems version is:
gem --version
This will output the version number directly, for example:
3.2.3
For more comprehensive information including Ruby version and platform details:
gem env
This displays output similar to:
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.3
- RUBY VERSION: 2.7.0 (2019-12-25 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
- USER INSTALLATION DIRECTORY: /home/user/.gem/ruby/2.7.0
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.7.0
- /home/user/.gem/ruby/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
If you're using RVM or rbenv, you can check versions for different Ruby installations:
rvm list gemsets
Or for rbenv:
rbenv versions
Then check the version for each Ruby installation:
rbenv global 2.7.0
gem --version
If you need to update RubyGems:
gem update --system
You may need sudo privileges for system-wide installation:
sudo gem update --system
If you encounter the "command not found" error:
sudo apt install ruby-full
This installs Ruby along with RubyGems on Ubuntu.
When writing scripts that require specific RubyGems versions:
if Gem::Version.new(Gem::VERSION) < Gem::Version.new('3.0.0')
abort "RubyGems 3.0.0 or later required"
end
The simplest way to check your RubyGems version is through the terminal. Open your Ubuntu terminal and run:
gem --version
This will output the currently installed version, for example:
3.1.6
For more detailed information about your RubyGems installation, use:
gem env
This command displays comprehensive environment information including:
- RubyGems version
- Installation directory
- Ruby version compatibility
- Configuration details
You can also verify the version through IRB (Interactive Ruby):
irb
require 'rubygems'
Gem::VERSION
This method is particularly useful when debugging Ruby scripts that depend on specific gem versions.
To see which version is available in Ubuntu's official repositories:
apt-cache policy rubygems
This helps determine if you're using the system-packaged version or a manually installed one.
When working with multiple Ruby projects, consider using a version manager:
rvm rubygems current
# or
rbenv gemset list
These tools help maintain different RubyGems versions for different projects.