How To Install a Ruby Gem

by Mr How on November 9, 2008 · 2 comments

RubyGems is the de facto packaging and package management system for Ruby libraries. Nearly all Ruby libraries are available as “gems” so it’s essential to know how to install them.

Prerequisites

On Ruby 1.9 and after, RubyGems is included with Ruby. For those using earlier versions (1.8.x, primarily) some installation may be needed.

Linux

Download the latest tarball (.tgz file) of RubyGems from its RubyForge repository. At the time of writing, this will be http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz but there may be a newer one now.

Mac OS X

Mac OS X 10.5 already comes with Ruby and RubyGems installed, so there’s no preparation needed.

Windows

If you used the one-click installer, RubyGems will already be installed. If not, follow these instructions.

Using RubyGems

Installing a Gem

All gems have a specific name. Once you know the name of the gem you want to install, on most platforms you can run:

gem install gem-name-here

By default, all gems are assumed to be hosted at RubyForge, so if a gem is not located at RubyForge (such as a gem hosted at Github, say), special installation instructions will be given where you suffix a URL on to the above line.

Note that on OS X and Linux / other UNIXes, if you are not running as root, you may need to use sudo to install your gems properly:

sudo gem install gem-name-here

In some situations, the RubyGems client will ask you which version of a specific gem you want to install. Typically you’ll want to choose the most recent version (the one with the highest version number) but you need to be careful you choose the right gem for your platform. For example, there may be a Windows gem and a “Ruby” (generic, will run on UNIX-based platforms) option, and you need to choose correctly.

Updating your Gems

Run the following:

gem update

Alternatively, you can run gem install again for the gems of your choice to force an upgrade on specific gems only.

Listing the Gems Installed

You can easily get a list of all of the Ruby gems that are installed on your computer:

gem list

Removing / Uninstalling a Gem

gem uninstall gem-name-here

If there are multiple versions of the same gem on your machine, this will not remove them all indiscriminately. You can choose which version to remove.

Further Reading

{ 2 comments… read them below or add one }

1

Mr How 11.09.08 at 12:26 am

Just a test comment. Sorry!

2

Mr How 11.09.08 at 12:34 am

Hello.. This is a test of some code in a comment.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>