As most programming languages, Ruby leverages a wide set of third-party libraries.
Most of them are released in the form of a gem. RubyGems is
a Ruby packaging system designed to facilitate the creation, sharing and
installation of libraries (in some ways, it is a distribution packaging
system similar to, say,
apt-get, but targeted at Ruby software). Ruby
1.9 comes with RubyGems by default, while previous Ruby versions require
to install it by hand.
Some other libraries are released as archived (.zip or .tar.gz)
directories of source code. Installation processes may vary,
INSTALL file is available with instructions.
Let’s take a look at finding libraries and installing them for your own use.
The main place where libraries are hosted is RubyGems.org,
providing Ruby libs as gems. You may browse the website directly, or use
gem search -r, you can inspect RubyGems repository. For
gem search -r rails will return a list of Rails-related
gems. Without the
-r) option, you would perform a local
search through you installed gems. To install a gem, use
[gem]. Browsing installed gems is done with
gem list. For more
information about the
gem command, see below or head to RubyGems’
There are other source of libraries though. RubyForge used to be a popular home for Ruby libraries, but last years saw the rise of Github as one of the main ruby-related content repository. Most often a gem source code will be hosted on Github while being published as a fully-fledged gem to RubyGems.org.
The Ruby Application Archive (or RAA) is a directory of all manner of Ruby software, categorized by function, but it is not quite used anymore. You probably don’t want to go there.
A few more words about RubyGems
Here is a quick review of the
gem command for your daily use. More
detailed documentation is available, covering all aspects of this
Searching among available gems
The search command can be used to look for gems, based on a string. Gems which names contain the specified string will be listed in return. For instance, to search for the “html”-related gems:
$ gem search -r html *** REMOTE GEMS *** html-sample (1.0, 1.1)
-r flag indicates that we want to inspect the
official RubyGems.org repository. Without this flag, you would perform a
local search (among your installed gems).
Installing a gem
Once you know which gem you would like to install, for instance the popular Rails:
$ gem install rails
You can even install just a certain version of the library, using the
$ gem install rails --version 3.0
Listing all gems
For a complete list of all gems available on RubyGems.org:
$ gem list -r
To list only local gems:
$ gem list
Documentation is available inside your terminal:
$ gem help
gem help commands is very useful as it outputs a list of