This guide will walk you through installing ruby, rails, and passenger with Apache onto an Ubuntu 12.04 machine. It should give you everything you need to get a site up and running.


Update apt-get

You should always make sure things are kosher before starting

sudo apt-get update

Create a downloads directory and navigate to it

mkdir ~/downloads
cd ~/downloads

Now you're ready to go.


The ruby source can be found at:

Download and extract source

Download and extract the source files from the link above for the specific version you want to install. For me, I was installing version 2.0

tar -xzvf ruby-2.0.0.-p451.tar.gz

This will unpack the source to the ruby-2.0.0-p451.tar.gz directory for your use.

Install pre-requisites

These are necessary to build the ruby source code

sudo apt-get install build-essential
sudo apt-get install openssl
sudo apt-get install libreadline6
sudo apt-get install libreadline6-dev
sudo apt-get install curl
sudo apt-get install git-core
sudo apt-get install zlib1g
sudo apt-get install zlib1g-dev
sudo apt-get install libssl-dev
sudo apt-get install libyaml-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt-dev
sudo apt-get install autoconf
sudo apt-get install libc6-dev
sudo apt-get install ncurses-dev
sudo apt-get install automake 
sudo apt-get install libtool

Running the install

Change to the source direcotry

cd ruby-2.0.0-p451

Now we will configure the make file. Running configure checks that we have everything needed to install and generates a make file for that will be used to compile the software.


Now lets compile it and verify things are ok.

make test

Finally install it

sudo make install

This will tell you where it puts everything, but for your convenience, this is where it installed for me (useful for removing this verion if you so desire):

installing binary commands:   /usr/local/bin
installing base libraries:    /usr/local/lib
installing arch files:        /usr/local/lib/ruby/2.0.0/i686-linux
installing pkgconfig data:    /usr/local/lib/pkgconfig
installing extension objects: /usr/local/lib/ruby/2.0.0/i686-linux
installing extension objects: /usr/local/lib/ruby/site_ruby/2.0.0/i686-linux
installing extension objects: /usr/local/lib/ruby/vendor_ruby/2.0.0/i686-linux
installing extension headers: /usr/local/include/ruby-2.0.0/i686-linux
installing extension scripts: /usr/local/lib/ruby/2.0.0
installing extension scripts: /usr/local/lib/ruby/site_ruby/2.0.0
installing extension scripts: /usr/local/lib/ruby/vendor_ruby/2.0.0
installing extension headers: /usr/local/include/ruby-2.0.0/ruby
installing rdoc:              /usr/local/share/ri/2.0.0/system
installing capi-docs:         /usr/local/share/doc/ruby
installing command scripts:   /usr/local/bin
installing library scripts:   /usr/local/lib/ruby/2.0.0
installing common headers:    /usr/local/include/ruby-2.0.0
installing manpages:          /usr/local/share/man/man1
installing default gems:      /usr/local/lib/ruby/gems/2.0.0 

Verify the version of Ruby and Ruby Gem

You can check the version with

ruby -v
gem -v

Install Rails

Now that you have ruby successfully installed, you can install rails

Update gem

sudo gem update --system

Install rails

I'm installing a specific version of rails here. You can specify the version with -v or you can install the latest by leaving this options off

sudo gem install rails -v3.2

You can check the version with

rails -v

Install Apache

You can refer to the Apache install instructions provided by Ubuntu for full infromation I'll go over some of the confi options

Install Apache

sudo apt-get install apache2

This will install the server named apache2 and configuration files in located in /etc/apache2.

Install Passenger for Apache

You can now install passenger from gem

sudo gem install passenger

You can execute the passenger installer for apache by running the following

sudo passenger-install-apache2-module

I had depencencies that I needed to install, the Passenger installer will tell you what you need to install. After installing these, rerun the installer:

sudo apt-get install libcurl4-openssl-dev
sudo apt-get install apache2-threaded-dev
sudo apt-get install libapr1-dev
sudo apt-get install libaprutil1-dev

Configure Passenger

Now that passenger for apache is installed, we can install the module in the apache configuration file

sudo vim /etc/apache2/httpd.conf

At the bottom of this file include the supplied module loader supplied by the Passenger installer.

LoadModule passenger_module /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.40/buildout/apache2/
<IfModule mod_passenger.c>
  PassengerRoot /usr/local/lib/ruby/gems/2.0.0/gems/passenger-4.0.40
  PassengerDefaultRuby /usr/local/bin/ruby

Add the path information for your site. The below maps the root directory to a special path in /usr/local/www where my application source is installed:

<VirtualHost *:80>
  DocumentRoot /usr/local/www/redmine/public
  RailsBaseURI /
  <Directory /usr/local/www/redmine/public>
    AllowOverride all
    Options -MultiViews

Now restart Apache

sudo service apache2 restart