The Cheatsheet discuss RubyGems commands for daily use. RubyGems is a package manager for the Ruby programming language. It provides a convenient way to distribute and manage software packages, called GEMs. With RubyGems, developers can easily install, uninstall, and manage Ruby libraries and applications. It simplifies obtaining and managing the dependencies needed for a Ruby project by automatically resolving and installing the GEMs required.
The term gem is related to the tool provided by RubyGems. GEM (capital letters) means the library to be managed by the command gem at the command line. |
RubyGems also provides a centralized repository, the RubyGems website at rubygems.org, where developers can publish their GEMs for others to use. The website serves as a searchable catalog of available GEMs, allowing developers to discover and download GEMs for their projects.
In addition to the default RubyGems repository, developers can configure their own GEM sources or specify alternative sources when installing GEMs. This flexibility allows private GEM repositories or custom sources to be used as needed. |
RubyGems comes pre-installed with a Ruby installation. It provides a command-line interface, the gem
command, for performing various operations, such as installing GEMS, listing installed libraries, updating GEMs, and managing library sources.
Here are common commands you can use with the RubyGems gem
command:
-
install — Installs a GEM from the default RubyGems repository
-
uninstall — Uninstalls a GEM
-
update — Updates installed GEMs to their latest versions
-
search — Searches for GEMs matching a specific term
-
list — Lists all installed GEMs
-
info — Provides information about a specific GEM
-
cleanup — Removes old versions of installed GEMs, keeping only the latest version
The following examples give your an overview of the most common used commands managing Ruby GEMs for daily use. All examples are focussing the J1 template to make it easier for users using the template system. Anyway, all commands can be used for any Ruby Appication by simply replacing the name of the GEM as required.
Install commands
The install
command installs software packages (libraries) in the Ruby programming language. The command will then search for the GEM specified on the RubyGems website (or a diifrerebt GEM repository configured), download it, and finally install it on your system.
Install from a Gemfile
Add this line to your application’s Gemfile:
gem 'j1_template', '~> 2023.4.2'
and install the locally created RubGem as:
gem install --local j1-template --no-document
Install globally
tbd
gem install j1-template
Install with no docs
tbd
gem install j1-template --no-document
Install userized
tbd
When you use the --user-install
option, RubyGems will install the GEMs to a directory inside your home directory under ~/.gem/ruby/3.1.0
for Ruby version 3.1.x
. The commands provided by the GEMs you have installed will end up in folder ~/.gem/ruby/3.1.0/bin
.
gem install j1-template --user-install --no-document
For GEMs installed userized that contain programs, you need to add the folder ~/.gem/ruby/3.1.0/bin
to your PATH
environment variable to get access.
Install a specific version
tbd
gem install j1-template -v 2023.4.2 --user-install --no-document
You can also use version comparators like >=
or ~>
.
gem install j1-template -v "~> 2023.4.2" --user-install --no-document
Install from a different source
tbd
gem install j1-template -v 2023.4.2 --source 'https://gem.fury.io/jekyll-one-org/' --user-install --no-document
Uninstall commands
tbd
Update commands
tbd
Search commands
tbd
List commands
tbd
Info commands
tbd
Cleanup commands
tbd
Clean up old GEM versions
To clean up old versions on your GEM_PATH
of installed gems use below command:
gem cleanup <GEMNAME …>
The cleanup command removes old versions of gems from GEM_HOME that are not required to meet a dependency. If a gem is installed elsewhere in GEM_PATH the cleanup command won’t delete it.
If no gems are named all gems in GEM_HOME are cleaned.
Update Rubygems
gem install rubygems-update
update_rubygems
gem update --system