Rocking With Rails 3 On CentOS 5
Written on a late Friday evening, posted on May 20, 2011.
The last two projects I’ve worked on have involved setting up Ruby on Rails on CentOS 5 in order to run test and production sites. The process is really quite simple, though there are a few things I’ve discovered along the way.
CentOS 5 is a great server OS—my personal favorite. A few days ago I was setting up a server that came with Ubuntu 10.04 installed. After attempting for a couple of hours to get Ruby, Rails, nginx and Passenger up and running I finally decided to switch it to CentOS instead. Luckily MediaTemple makes switching OS merely a matter of selecting a radio button.
After a few minutes CentOS was installed and from there things went well. Getting Ruby and Rails 3 working on CentOS 5 isn’t difficult at all. However, while some of the software is available via the “yum” package manager, some is not, and some packages are outdated. You just have to do what’s necessary to get everything installed and then you’re all good!
Oversimplified instructions
- First of all you should install the development tools via yum so that we can compile the software we need.
- Then you’ll want to install Git. It’s not available in yum so download the source from the Git website (use wget), unpack it (tar zxvf) and compile it (./configure && make && make install).
- If you want to easily switch between versions of Ruby, look into RVM (Ruby Version Manager), but just having the latest version will suit my needs.
- The latest version of Ruby isn’t available via yum either so download the source and compile it. It should install just fine—run “ruby -v” to check.
- Ruby also installs RubyGems so we can now go ahead and install our gems. You can also run an update if you want to.
- Run “gem install rails” to install Rails 3 and its dependencies. Try creating and starting an application. If it complains about a missing sqlite3-ruby gem, download the SQLite source code and compile it, and run “sudo gem install sqlite3-ruby” to install the missing gem. Once again, yum doesn’t have the required version.
- Choose which web server you want to use (nginx or Apache) and install it along with Phusion Passenger to run Rails applications. If you choose nginx, simply download Passenger and run the nginx installer—it will compile nginx for you. To run Apache, install the yum httpd package. Then download, run and follow the instructions of the Passenger Apache module installer.
- Set up your vhosts in your Apache or nginx configuration file.
There are probably steps I haven’t mentioned but my point is; just tackle your way through the software installation. If yum doesn’t have what you need, just compile it from source. It worked well for me. While there are some third-party repositories for yum packages, I rather compile the software myself.
Hopefully you can now deploy your application to the server. I highly suggest you use Capistrano for deployments and rollbacks, among many other tasks it can be used for. Further reading on running Rails 3 on CentOS 5:
7 Steps To Rails On CentOS
CentOS 5 and Rails 3 and Ruby 1.9.2
Install Ruby Version Manager (RVM) on CentOS 5.5
Install Ruby 1.9.2 + Passenger On Centos 5.5 x32
Install Ruby 1.9 on CentOS
Leave a comment or share this on Twitter.