Wednesday, August 12, 2009

How to install Ruby and RubyGems

Ruby comes preinstalled on Mac OS X and most Linux installations. Windows doesn't come with Ruby, but it's easy to get it with the One-Click Installer: see

If you're on a Unix/Linux system and you don't have Ruby installed (or you want to upgrade), your distribution's package system may make a Ruby package available. On debian GNU/LINUX, it's available as the package ruby-[version]: for instance, ruby-1.8 or ruby-1.9. Red Hat Linux calls it ruby; so does they macports Mac OS X.

If all else fails, download the Ruby source code and compile it yourself. You can get the Ruby code through FTP or HTTP by visiting

Many recipes in this blog require that you install third party libraries in the form of Ruby gems. In general, we prefer standalone solutions (using only the Ruby standard library) to solutions that use gems, and gem-based solutions to ones that require other kinds of third-party software.

To get started, all you need to know is that you first download the Rubygems library from Unpack the tarball or ZIP file, change into rubygems-[version] directory, and run this command as the superuser:

$ ruby setup.rb

The RubyGems library in the Windows One-Click Installer, so you don't have to worry about this step on Windows.

Once you've got the Rubygems library installed, it's easy to install many other pieces of Ruby code. When a recipe says something like "Ruby on Rails is available as the rails gem," you can issue the following command from the command line (again, as the superuser):

$ gem install rails --include-dependencies

The RubyGems library will download the rails gem (and any other gems on which it depends) and automatically install them. You should then be able to run the code in the recipe, exactly as it appears.

The three most useful gems for new Ruby installations are rails (if you intend to create Rails applications) and the two provided by the Ruby Facets project: facets_core and facets_more. The Facets Core library extends the classes of the Ruby standard library with generally useful methods. The Facets More library adds entirely new classes and modules. The Ruby Facets homepage ( has a complete reference.

Some Ruby libraries (especially older ones) are not package as gems. Most of the nongem libraries mentioned in this article have entries in the Ruby Application Archive (, a directory of Ruby programs and libraries. In most cases you can download a tarball or ZIP file from RAA, and install it with the technique.


  1. It's macports ( on Mac OSX, not DarwinParts

  2. i already update my post thanks :)

  3. hi! friend... Thanks for the sharing... easy to download

  4. Hi Mate, I have installed Ruby on windows successfully, but when i tried to install cucumber using the command prompt "gem install cucumber" it fails. Do I need to setup any more which I haven't? Can you please help me on this.