Installing rubygems on CentOS 5.5

Here is how to get rubygems working on CentOS 5.5.

  1. Remove the old Ruby packaged with CentOS.
    $ sudo yum erase ruby
  2. Make sure you have zlib and zlib-devel installed.
    $ sudo yum install zlib zlib-devel
  3. Install a newer Ruby like 1.8.7-p299.

    $ wget http://core.ring.gr.jp/archives/lang/ruby/1.8/ruby-1.8.7-p299.tar.bz2
    $ bunzip2 ruby-1.8.7-p299.tar.bz2
    $ tar xf ruby-1.8.7-p299.tar
  4. The following is probably not optimal, but I do it anyway. In the ruby directory, edit ext/Setup and uncomment out the packages that interest you. I like iconv, openssl, socket, syslog, and zlib. Make sure you have zlib. The alternative (probably recommended) method is to not statically link this modules and instead compile and install the packages individually, but I forget how to do that and didn't have time to learn.

  5. Install ruby.

    $ make
    $ make test
    $ sudo make install
  6. Ensure ruby is in the path. ruby likes to install itself in /usr/local/bin, which CentOS usually doesn't have in the path.
    $ which ruby     # Not found?  Add /usr/local/bin to your $PATH.
  7. Ensure ruby is installed.
    $ ruby -v
  8. Install rubygems.

    $ wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
    $ sudo ruby setup.rb
  9. Ensure rubygems works.

    $ gem list # Doesn't work? Error about zlib? Make sure you have zlib-devel installed (see step 2)! Then make; make install ruby again.