A myriad of fascinating and useful libraries are out there for Ruby, many released as a convenient gem file. Other libraries are released as archived (.zip or .tar.gz) directories of source code. Let’s take a look at finding libraries and installing them for your own use.

Finding Libraries

RubyForge is a popular home for Ruby libraries. One good spot to browse is its software map, which lists libraries by topic. (If you end up creating your own libraries, you can register your project at Rubyforge to get free Subversion access, web space, and mailing lists.)

The Ruby Application Archive (or RAA) is a directory of all manner of Ruby software, categorized by function. Right now, the Database category has the most entries, leading by 1 over Net. HTML and XML are also popular categories. There are even 4 Physics entries.

Using RubyGems

While the Windows installer includes RubyGems, many operating systems do not. Please refer to Installing RubyGems below, if these commands do not work for you.

Searching for Gems

The search command can be used to look for gems of a certain name. To search for the word “html” in the name of a gem:

 $ 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 indicates that we’ll be searching 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 gems you’ve installed, leave off the flag.

 $ gem list

For more on using RubyGems, see the official manual, which includes examples for using gems in your Ruby scripts.

Installing RubyGems

To install RubyGems, download RubyGems 0.9.0 from its downloads 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 some further direction on how to install Ruby, check out the installation chapter in the RubyGems manual.