Running a Rails app in production using rbenv, Apache and Passenger

Recently, I upgraded NZ Walks Info to Rails 3 and Ruby 1.9.3. In order to run this new setup successfully, I needed to upgrade the Ruby version on the server. I chose ruby-build and the rbenv Ruby Version Manager to do so and would like to share some simple instructions that worked for me.

The Setup

I am running the site on a Linode server running Ubuntu Linux 10.04. Here’s the software I use:

  • Ruby 1.8.7: installed system-wide using apt-get, located in /usr/lib/ruby
  • Apache2
  • Passenger 3

Ruby was going to be upgraded to version 1.9.3 while the other parts stayed the same. However, Passenger 3 needed to be reinstalled to work with the new version of Ruby installed via rbenv.

Installing Ruby 1.9.3 on Ubuntu 10.04 using rbenv

I found this Gist by Ben Woodward with instructions on how to install rbenv system-wide. I figured, when installing it like this I would less likely run into permission problems.

Here’s the essential part of the Gist, adjusted to install Ruby 1.9.3:

# Install rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv

# Add rbenv to the path:
echo '# rbenv setup' > /etc/profile.d/rbenv.sh
echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh

chmod +x /etc/profile.d/rbenv.sh
source /etc/profile.d/rbenv.sh

# Install ruby-build:
pushd /tmp
  git clone git://github.com/sstephenson/ruby-build.git
  cd ruby-build
  ./install.sh
popd

# Install Ruby 1.9.3-p0:
rbenv install 1.9.3-p0
rbenv global 1.9.3-p0

# Rehash:
rbenv rehash

Confirming that I am running the new version:

ruby -v
# ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]

Updating Passenger

Now I needed to update Passenger to work with the new version of Ruby. All there was to do was to install the passenger gem, following the instructions on their website:

gem install passenger

passenger-install-apache2-module

At the end of the installation, I got the configuration lines to paste into the Apache2 config file. I replaced my old settings with these updated ones:

LoadModule passenger_module /usr/local/rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
PassengerRuby /usr/local/rbenv/versions/1.9.3-p0/bin/ruby

Bundler

The only thing that was missing to be able to deploy my Rails 3/Ruby 1.9 version of my app was to install Bundler:

gem install bundler

Done

This was all that needed to be done to upgrade the Ruby version on my Linux/Ubuntu system using rbenv. I hope these instructions will help someone else, too.

Notes

  1. danielpietzsch posted this