Installing Ruby 1.9.1 on CentOS

I recently installed Ruby 1.9.1 on CentOS (/Redhat). I had to jump
through a few hoops, so I thought I would share in case anyone else is
dealing with similar problems.

When it comes to setting up Ruby on Rails many of us developers are on
our own as far as configuring the environment. While I love working in
Linux, I am hardly a Linux administrator. I've learned a few things
along the way while setting up my Ruby on Rails environment in CentOS,
and I thought I would share these lessons here (and record them for my
own future use).

Note: Before doing any of this, you should probably know your way
around Linux with some degree of confidence, and you will need root
access. Its probably also a good idea to have openssh-server installed
and configured. I recommend PuTTY as an SSH client for Windows.

   1. On a fresh Redhat installation you may first have to install
GCC. You can simply install GCC and other libraries you need, or you
can run:

      yum groupinstall 'Development Tools'

      This command will install all kinds of 'stuff' that is not
really necessary though.

This is necessary especially if you are building a current version of
Ruby on Rails (e.g. 1.9.1, which includes GEM but does not have a yum
installer for CentOs or Redhat). Install these items before you
proceed to build (make and make install) Ruby from source:

yum install gcc
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel

Note: Later, if you go to run gem and get an error including, "no such
file to load -- zlib," it means you forgot to install zib and/or zlib-
devel before building Ruby. You'll have to rebuild and re-install.

   1. Download the Ruby source (from The file
comes in a tarball, so once it is download extract is somewhere (~)

      tar xvf <ruby-1.9.2-p136.tar.gz>

      (tar xvf handles the unzipping as well.)
   2. If installing over an existing Ruby installation, it may be best
NOT to overwrite that installation and simply add a suffix to your
Ruby install (and put it in /usr/local).

      cd <ruby-1.9.1>
      ./configure --program-suffix=19 --enable-shared --with-readline-
      make && sudo make install

      The default installation on Redhat/CentOS will be /usr/local/
ruby. Make sure this is the case by doing:

      which ruby
      ruby -v (verify 1.9.1. is installed)

If you installed with a program-suffix (like in the ./configure
example above), Ruby will be installed as ruby19 (and gem as gem19).
You may want to make a symlink to point to your version of Ruby, but
its perfectly fine to continue to reference "ruby19" in your scripts.

Strangely, after attempting to launch my first app after the CentOS
installation of Ruby 1.9.1, I received an error that openssl could not
be loaded. This was resovled by re-building Ruby's openssl library.
Details here. Also, note the fact that I did a yum install of openssl
and openssl-devel beforehand.


      Install mod_rails (Phusion Passenger) and setup up Apache. This
is your Ruby server deployment.

      Set up your database. I like PostgreSQL, but I've have some
difficulty getting PgAdmin to run on CentOS. There are a few

      yum install gtk+-devel
      yum install gtk2-devel
      yum install libxml2-devel
      yum install libxslt-devel

      After gtk is installed you will have to install wxGTK and
wxWidgets (don't forget wxWidgets contribs) before you can build/
install PgAdmin. PostgreSQL installed easily, but getting PgAdmin
going was more effort.

      Run your app! If you are running CentOS/Redhat in a virtual
machine you will likely need to set up a bridged network adapter. In
VirtualBox go to Devices->Network Adapters. It is likely that, if
using the default configuration, Adapter 1 is attached to NAT. Add a
second adapter attached to "Bridged Adapter," and within your CentOS
network configuration enabled it. (By the way, if you are going to run
PgAdmin on Windows or some other server, make sure your Linux Posgres
server has the PostgreSQL post, e.g. 5432, open to TCP connections.)

(Read all about CentOS/Redhat network configuration here.)

To access your Apache or Webrick server externally you will have to
use that Bridged network adapter (probably eth1). From a terminal run
ifconfig -a to view the inet address. Apache typically uses port 80
and Webrick typically uses port 3000 (this is basic stuff, and if it
is new to you, you may need to read up a little on web servers before
doing much more with Rails).

As you can see, there were some hoops to jump through and some
problems to resolve. These problems stem mostly from the fact that
there is presently (01/19/2011) no yum install for Ruby 1.9.1. Once
everything is up and running, however, myself and others have had no
problem running Ruby 1.9.1 on CentOS/Redhat.

Related links:
PostgreSQL Installation on CentOS

Rails 3 + PostgreSQL