There are many fascinating and useful libraries available for Ruby, many of which are available as a convenient gem file. Other libraries are released as compressed archive (.zip or .tar.gz) files. Let's look at how to find and install libraries.
Finding Libraries
RubyForge is a popular home for Ruby libraries. A good place to browse is its software map, which lists libraries by topic. If you end up creating your own library, you can register your project at RubyForge to get free Subversion hosting, web space, and mailing lists.
The Ruby Application Archive (RAA) is a directory of all manner of Ruby software, categorized by function. Currently, the Database category has the most entries. Net is close behind.
Using RubyGems
The Windows installer includes RubyGems, but many platforms require you to install it yourself. See the installation instructions below.
Searching for Gems
The search command can be used to look for gems by name. To find a gem with the word "html" in its name, type:
$ gem search html --remote
*** REMOTE GEMS ***
html-sample (1.0, 1.1)
A sample Ruby gem, just to illustrate how RubyGems works.
(The --remote flag means we search the official Rubyforge gems.)
Installing a Gem
Once you know which gem you'd like to install:
$ gem install html-sample
You can even install just a certain version of the library using the --version flag:
$ gem install html-sample --version 1.0
Listing All Gems
For a complete list of all gems at Rubyforge:
$ gem list --remote
To list only the gems you have installed, leave off the flag:
$ gem list
For more information on using RubyGems, see the official manual, which includes examples for using gems in your Ruby scripts.
Installing RubyGems
To install RubyGems, download the
current version of RubyGems
from its project page. Extract the archive and run setup.rb.
On some operating systems you may need to do this as root.
For example, on Linux:
$ tar xzvf rubygems-0.9.0.tar.gz
$ cd rubygems-0.9.0
$ su -
# ruby setup.rb
If you need further help, see the installation chapter of the RubyGems manual.