Managing your Ruby Gems with RubyGems and the gem command.
RubyGems is a package manager
RubyGems is a package manager for Ruby gems, and has been a part of Ruby itself since version 1.9.2.
Ruby gems are hosted on gem servers, the most important of which
is rubygems.org. The command line interface to the rubygems.org API is via
the gem command. With gem you can search
gem servers, download gems, install, update, and delete gems. There are other commands as well.
You can read the docs for
Installing a gem puts the contents of the gem package in a directory with other gems. These
collections of installed gems are sometimes called gemsets.
So how does a Ruby program locate and use the code in a gem?
The Ruby Kernel consults a load path when it encounters a *require * statement, looking for
a gem that matches the required name.
When a Ruby script *requires 'rubygems'*, rubygems
replaces Kernel#reqire with its own #require.
Now *require* will invoke rubygems#require to activate the specificed gem. If the required gem is already
on the load path ($LOAD_PATH), rubygems#require sends control to Kernel#require. If the required gem
is not found on the current load path, Rubygems finds
the specified gem's code and modifies the Ruby load path ($LOAD_PATH) to include the gem's directory.
In this way the load path is constructed to point to the code for installed gems.
On an ending note, Ryan Tomayako of Sinatra fame makes an excellent point that
using require ‘rubygems’ in library code and apps is probably the wrong thing to do.
You can read his explanation at this Gist.