Updating Rubygems: a necessary step before installing the Amazon gem

This article shows you how to install a gem (a ruby package) that provides access to Amazon APIs for EC2, ELB, and RDS. But along the way it also provides important information on the entire Rubygems environment. This information is critical for anyone who is tasked with maintaining a working Ruby environment.

Yesterday I posted an entry about using Ruby to access the Amazon EC2 API and I mentioned a gem that provided the classes needed to make such access easy. Gem is the package system for ruby, and fills a role similar to one that CPAN provides for perl. The Amazon gem is called amazon-ec2 and it is written and supported by Glenn Rempe. The code base is stored at github and you can access the page here: http://github.com/grempe/amazon-ec2. The gem is also part of the standard repository of Ruby Gems located at rubyforge.org. This gem provides an interface not only for the EC2 API but also for the the elastic load balancing service (ELB), the autoscaling service, and the relational database service (RDS).

When I first tried to get this gem working I encountered a number of problems, all with the environment on my system. At first I attributed this to the beta nature of the gem itself, but I have recently discovered that the problem was entirely with my Ruby environment. If you are interested in using Ruby to access the Amazon API then you will first want to install a working version of the gem. This short article will help pave the way.

Before installing any more gems you must make sure that the gem application itself is up to date. An out of date gem application was the source of all my problems. Once I updated it, the installation of amazon-ec2 went smoothly and without a hitch. Many current Linux distros provide a package that will install the Ruby gem application. Some of them provide a very recent version of it but others, like CentOS, provide a version that is years out of date. It is crucial that this be updated if you want a smoothly operating Ruby environment. The most recent versoin of gem is 1.3.7. You can check the version of gem with gem -v.

Upgrading gem is easy and can be accomplished in several ways. Although the gem application has a built in update command I don't recommend you use it for this upgrade, as it doesn't always work correctly. To perform the upgrade try this method first:

gem install rubygems-update
update_rubygems

If this works then gem has been updated to the latest version. However, if the gem install command fails with a message saying something similar to "could not find gem rubygems-update locally or in a repository" then you will need to resort to the second method. For this you will need to download the tarball and install it by hand. Browse to the following page: http://rubyforge.org/frs/?group_id=126. Select and download the latest version of rubygems as either a tgz or a zip file. Extract the contents of this file in to a temporary directory, then run the script setup.rb contained within. Assuming you have downloaded the tgz file as rubygems-1.3.7.tgz, perform the following steps:

cp rubygems-1.3.7.tgz /tmp
cd /tmp
tar xzf rubygems-1.3.7.tgz
cd rubygems-1.3.7
ruby setup.rb

Either of these methods should ensure that you have the latest version of gem installed on your system. Then you can install the latest gems easily and with confidence that they will install correctly. Now if you still want to get the amazon ec2 gem it is as easy as this:

gem install amazon-ec2