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.
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.
As stated on the RubyGems website, “RubyGems is the premier ruby packaging system. It provides a standard format for distributing Ruby programs and libraries, and an easy to use tool for managing the installation of gem packages.” In some ways, it is a distribution packaging system similar to, say, apt-get, targeted at ruby software. The official gems repository is Gemcutter.
While the Windows installer includes RubyGems, many operating systems do not. Please refer to Installing RubyGems below, if next gem commands do not work for you.
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 Gemcutter gems.)
Once you know which gem you’d like to install:
$ gem install html-sampleYou can even install just a certain version of the library using the --version
flag.
For a complete list of all gems at Gemcutter:
$ gem list --remoteTo list only gems you’ve installed, leave off the flag.
$ gem listFor more on using RubyGems, see the official manual, which includes examples for using gems in your Ruby scripts.
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.rbIf you need some further direction on how to install Ruby, check out the installation chapter in the RubyGems manual.