7 Steps to Rails on CentOS

Red Hat Linux (and its recompiled cousin, CentOS)  has a fantastic reputation for stability and maturity.  However, this often means that packages included with the OS are somewhat out-of-date by the time the distribution is released.  For example, the latest version of CentOS is 5.5, and the version of Ruby that ships with it is version 1.8.5, which dates back to August 2006.  Even the Ruby group recommends using nothing less than 1.8.7 for Rails development.

So how do you get the stability of Red Hat with the goodness of Ruby? Compile from source to get the latest, greatest version.  Here’s how:

1)  Install CentOS 5.5
To save yourself alot of headaches during the installation, check to see if you have the “Development Tools” group installed with this command:

# yum grouplist |grep -i Development

If you don’t have it, install the package group with this command:

#yum groupinstall "Development Tools"

Note that you may also have the older version of Ruby installed via RPM’s.  You can check to see if you have it with this command:

# rpm -qa |grep ruby

If you discover an older version, uninstall it before proceeding (rpm -e <package_name>).

2) Create a /sources directory and change to that directory.

3) Download and build Ruby.
Download the latest Ruby source code (latest version is 1.9.2-p0 as of this writing).

wget ftp://ftp.ruby-lang.org//pub/ruby/1.9/ruby-1.9.2-p0.tar.gz

Uncompress the tarball and build Ruby:

tar -zxvf ruby-1.9.2-p0.tar.gz
cd ruby-1.9.2-p0
make install

If you have all the proper dependencies, you should have no errors during the configure or make phases. This will install Ruby to the following directories:


Once the install is complete, verify the version of Ruby:

# ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036)

The Ruby source package also installs RubyGems, the Ruby package manager.  Verify the version of RubyGems:

# gem -v

4) Check for updated gems
Ensure you have the latest gem versions by running this command:

# gem update --system

5) Install the rake build language

# gem install rake

6) Install rails

# gem install rails

7) List the installed gems.

# gem list

That’s it! You now have a fully-installed Ruby on Rails stack.  However, Ruby also needs a back-end database and a web server for its presentation layer.   Future posts will detail how to install and integrate web server and database tiers with Rails.

23 Replies to “7 Steps to Rails on CentOS”

  1. This command
    yum grouplist |grep -i Development
    does not tell you whether or not it is installed. You need to know whether Development Tools is listed under “Installed Groups” or “Available Groups.” I suggest using the command “yum grouplist | less”

  2. Thanks, this was very helpful. A few notes from my experience:

    – I had to use sudo or root for certain steps (make install, gem install …)
    – For some reason after the install went smoothly the gem update –system command gave the following error:
    ERROR: Loading command: update (LoadError)
    no such file to load — zlib
    ERROR: While executing gem … (NameError)
    uninitialized constant Gem::Commands::UpdateCommand

    So I had to:
    cd ruby-1.9.2-p0/ext/zlib/
    ruby extconf.rb
    sudo make install

    After that all seems to be good.

  3. Thanks for this. Ended up with a bone-stock VM of CentOS 5.5 on a Mac host having to run this sequence:

    1. Make and ‘make install’ on the ruby sources
    2. yum install zlib-devel
    3. cd to ruby*/ext/zlib
    4. ruby extconf.rb
    5. make
    6. make install
    7. gem update –system
    8. etc…

  4. thanks for sharing this, helped me skip the long hours of trying to install rails on centos! woot! two thumbs up!! 😀 woot!!

  5. @Mike, I also recommend RVM. However, RVM can make scripting more difficult. If you are installing Ruby on a production machine that will only run one app at a time, RVM can be a lot more hassle than it is worth.

  6. Im trying to follow these directions on Red Hat 5.5 and Im getting the same errors when running the gem command that others have listed. But their fixes are not working for me, Ive installed the zlib-devel package but I cant find the extconf.rb file using the locate or whereis commands.

  7. @Chris

    the ext/zlib/extconf.rb file will be wherever you download/unzipped the ruby source. If you don’t remember where that is, try this:

    find / -wholename ‘*/ext/zlib/extconf.rb’

    If that doesn’t find anything, then you may have already deleted the ruby source, which means you’ll need to download it again.

  8. Definitely use RVM, if only because it lets you easily manage the roll-forward and roll-back of ruby and associated gemsets. I just completed a centos 6.0 install and what was needed was:

    yum groupinstall “Development Tools”
    bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    rvm get head
    rvm reload
    rvm install 1.9.2
    rvm use 1.9.2. –default
    rvm rubygems latest
    gem install rake
    gem install rails
    gem install mysql
    gem install sqlite3


Leave a Reply

Your email address will not be published. Required fields are marked *