Dec 3, 2008

Install Ruby Rails on Ubuntu Intrepid Ibex

I've talked about installing Rails on various versions of Ubuntu before. Each time there are little gotchas that make it worthwhile to post another version. This time we're using Ubuntu Intrepid Ibex and also switching from Mongrel to Phusion Passenger (mod_rails). My experience is that Phusion performs far better on lower ram machines. That being said, if you're interested, roll up your sleeves and follow along!

[Update: 04-20-2009]: There is now a version for Ubuntu Jaunty.

Step 1: As usual, the first thing we'll want to do is make sure your version of Intrepid Ibex 8.10 is up to date.:
sudo apt-get update
sudo apt-get dist-upgrade

Step 2: We'll be installing some software that needs to be built so we'll need to get packages required for compiling. In one swoop, you can type this command and get everything you need:
sudo apt-get install build-essential

Step 3: Once you've got the tools, it's time to install MySQL and Ruby. Just copy and paste this command into your terminal if you're in a hurry.
sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libterm-readkey-perl psmisc

If you hadn't previously installed MySQL you'll be asked to set a root password. Don't forget what you choose!

Step 4: Grab the latest ruby gems and install them. As always be sure to check to make sure you're grabbing the latest one. As of this writing it's 1.3.1 but it never hurts to confirm.
tar xvzf rubygems-1.3.1.tgz
cd rubygems-1.3.1
sudo ruby setup.rb

Once it's done you can remove the .tgz file and erase the rubygems-1.3.1 directory too.

Step 5: Make symlinks. Just in case the symlinks did not get created for you (the symlink for gem was missing for me so don't assume) go ahead and create them with these commands:
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

Step 6: Install Ruby on Rails! You can leave off the --no-rdoc and --no-ri switches if you're on a machine with plenty of ram. But just in case you've got a more modest setup (say 256MB or less) I'd just use the following:
sudo gem install rails --no-rdoc --no-ri

If you're just doing local development then congratulations you are done! If you want to deploy Ruby on Rails onto a server then it's time to grab Apache and Phusion.

Step 7: If you're still reading then it means you are going to put this sucker on a server for the whole world to see. The first thing you'll need is to install Apache:
sudo apt-get install apache2 apache2-mpm-worker apache2-prefork-dev apache2-utils apache2.2-common comerr-dev libapr1 libapr1-dev libaprutil1 libaprutil1-dev libdb4.6-dev libexpat1-dev libkadm55 libkrb5-dev libldap2-dev libmysqlclient15-dev libpcre3-dev libpcrecpp0 libpq-dev libpq5 libsqlite3-dev libssl-dev openssl-blacklist ssl-cert uuid-dev zlib1g-dev apache2-utils apache2.2-common comerr-dev libapr1 libapr1-dev libaprutil1 libaprutil1-dev libdb4.6-dev libexpat1-dev libkadm55 libkrb5-dev libldap2-dev libmysqlclient15-dev libpcre3-dev libpcrecpp0 libpq-dev libpq5 libsqlite3-dev libssl-dev openssl-blacklist ssl-cert uuid-dev zlib1g-dev

That's a lot of files compared to what we might see with a lighter webserver. Phusion makes it worth it though so let's just keep going. If you are prompted to install other packages after entering the above command just say Yes.

Step 8: We're going to create a directory for your application. In anticipation of Capistrano, let's put it in /var/www/myapp/current. Swap out the myapp with anything you like.
sudo mkdir -p /var/www/myapp/current

Once you've got the directory setup, go ahead and copy your Rails application there. You should also chown it for www-data for the moment.
sudo chown -R www-data:www-data /var/www/myapp/current/

Step 9:
Now that Apache is set up, let's install Phusion Passenger:
sudo gem install passenger
sudo passenger-install-apache2-module

Edit your Apache configuration file, and add these lines to the bottom:
   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8

Step 10: Now it's time to create your apache config and enable your site. There are plenty of examples on how to configure Apache out there. Create a file in your /etc/apache2/sites-available/ directory.. in our example we'll call it mywebsite, and populate it as required. You can also download this sample file if you want it.

Once that's done, it's time to enable the site in Apache and restart the webserver
sudo a2ensite-enable mywebsite
sudo /etc/init.d/apache2 restart

In case it's not already installed, let's grab the perquisites and then install the mysql gem. This will improve performance on your webserver:
sudo apt-get install libmysqlclient-dev
sudo gem install mysql --no-rdoc --no-ri

That's all there is! I always seem to miss some minor detail so feel free to leave a comment and I'll do my best to address any mistakes. For tech support I strongly encourage you to use the Ubuntu Forums!

For Ubuntu Hardy Heron (the current LTS release) see this link.


  1. thanks for the nice write up. I almost got everything working except I got stuck with 2 commands dealing with apache. I wonder if I'm doing something wrong here.

    $ sudo chmod -R www-data:www-data /var/www/myapp/current/
    chmod: invalid mode: `www-data:www-data'

  2. Yes, my bad.. please use chown -R instead of chmod.. I'll correct that in the writeup. Sorry!

  3. Thank you! I went through three other How to Install RoR on Ubuntu before I found yours. The first three didn't work, yours did.

  4. Hi, thanks for the pointers.

    Not sure if I ran through all steps correctly, but when I tried running a "hello world" app it came up with this error:

    no such file to load -- sqlite3

    Eventually, after some testing, I figured out I had to run:

    sudo gem install do_sqlite3

    and this seemed to fix the problem, might help someone else out there?

    Once again, thanks for posting this, was a great help

  5. Passenger updated since so you'll need:

    LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/

    in /etc/apache2/apache2.conf.

    I downloaded your site, and got up to the server restart (after creating a public folder) and got this error (sorry not familiar with RewriteEnginer--what next?)

    $ sudo mkdir /var/www/myapp/current/public
    $ sudo /etc/init.d/apache2 restart
    * Restarting web server apache2 Syntax error on line 7 of /etc/apache2/sites-enabled/mywebsite:
    Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

  6. Thanks for the great post! I skipped putting in 'mywebsite' and just did everything else. Seems to have worked, though I can't say I've tested it out fully!

    A note to any fellow newbies out there: My config file was in the /etc/apache/http.conf (one level up from the home folder) and to edit it, I had to type gksudo gedit /etc/apache2/httpd.conf at the command line and enter my password.

  7. Same problem as Vince, also

    sudo a2ensite-enable mywebsite

    did not work (command not found) but

    sudo a2ensite mywebsite seemed to work.

    However since I have the RewriteEngine problem, I'm wondering if using a2ensite instead of a2ensite-enable was the problem

    update: following this seemed to help...

  8. Vince, seems I'm getting closer.

    Thank you Amy, that step 9 could be clearer

    anyway, I still have problems. after restarting Apache2:

    Syntax error on line 190 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/httpd.conf: Cannot load /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/ into server: /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/ cannot open shared object file: No such file or directory

  9. Hi,

    adding /mods-available/passanger.load and passenger.conf could solve your problem.


    LoadMOdule passanger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/


    PassengerRoot /usr/usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
    PassengerRuby /usr/bin/ruby1.8

    and then, /etc/init.d/apache reload

    But still, it seems I cannot use Phusion PassengerPhusion Passenger....

    this seems difficult...well...keep on trying...

    wish you luck

  10. passenger has updted again. Use passenger-2.1.3 rather than 2.0.3

  11. I have a same case post here