How to install Rails 3.0 and Ruby 1.9.2 on Ubuntu

Published on September 01, 2010 by Toran Billups

Update 04/29/2012

If you are running an older version of ubuntu the guide below might still apply, but since the release of Ubuntu 12.04 this install has become a much simpler process. So simple in fact that you can basically do a 'gem install rails --version=3.1'. But since I'm big into automation I've also written a script that will produce a working Ubuntu development machine from a fresh install of Ubuntu 12.04. If you run the script you will have a fully functional ruby / python / node development machine.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

When ruby on rails 1.0 was released back in 2005 it was all the rage. And being someone who was often distracted by the next great web framework I decided to have a look. So in early 2006 I built a small application to see what all the hype was about. I immediately saw the value of a strongly opinionated framework, something the average asp.net developer like myself didn't know much about at the time.

Fast-forward to August 29th 2010 - Rails 3.0 was released. Just prior to this release I started looking at the web framework again and because I always strive for the optimal developer experience it meant I would need to quit my windows addiction. Not that you can't do ruby development on windows, but most of the time it's not worth the pain.

With that said, I paved my development machine and installed Ubuntu 10.04. But as I started looking around for a 'how-to' of sorts on installing rails 3 with ruby 1.9.2 I couldn't find a simple guide that got me up and running error free. Each time I started with a vanilla install of Ubuntu and ended up with what felt like a 'hacked together' development environment. But last night I decided to give it another try and document the steps needed for someone like me coming in with minimal linux experience.

Install RVM 1.0.1

First be sure to do a quick update before you get started.

sudo apt-get update

Next install curl and git so we can pull down ruby via rvm

sudo apt-get install curl git-core

Next you need to get the tar.gz for rvm 1.0.1

http://rvm.beginrescueend.com/releases/rvm-1.0.1.tar.gz

extract the contents and cd into the extracted directory when finished

tar xvzf rvm-1.0.1.tar.gz

Once inside the extracted directory run the installer from the command line

./install

After this is complete you need to edit your .bashrc file. First cd ~ and then Type 'gedit .bashrc'. Put the following at the bottom of the file.

[[ -s '$HOME/.rvm/scripts/rvm' ]] && source '$HOME/.rvm/scripts/rvm'

after you complete the above and save your changes, close gedit. Next close your terminal window and re-open it. Now if you type 'rvm -v' you should see a valid version 1.x

Install Ruby 1.8.7

First you need to pull down a few development packages

sudo apt-get install libruby1.8 zlib1g-dev libssl-dev libreadline5-dev build-essential

Next you need to install ruby 1.8.7 through rvm

rvm install ruby-1.8.7

After this is complete you need to set ruby 1.8.7 as the default for rvm

rvm use ruby-1.8.7 --default

Install rubygems and other dev essentials

first you need to add the ubuntu-on-rails ppa repository, sometimes they have newer versions of some Ruby components.

sudo add-apt-repository ppa:ubuntu-on-rails

After you add this be sure to do another update

sudo apt-get update

Next install the essential ruby packages

sudo apt-get install ruby rubygems irb ri rdoc rake

And a few more packages, odds are you will need them anyway

sudo apt-get install build-essential ruby1.8-dev libopenssl-ruby

After all the packages above are installed, add the gem path to your global PATH, so that executables new gems can be easily called from the command line.

export PATH=/var/lib/gems/1.8/bin:$PATH

After you run the above command, close the terminal window and re-open it.

Install Sqlite3

Install the sqlite development packages

sudo apt-get install sqlite3 libsqlite3-dev

Install the sqlite gem

gem install sqlite3-ruby

Install Ruby 1.9.2

Next you need to install ruby 1.9.2 through rvm

rvm install ruby-1.9.2

After this is complete you need to set ruby 1.9.2 as the default for rvm.

rvm use ruby-1.9.2 --default

Install Rails 3.0.0

Now install rails but be sure you DON'T use sudo

gem install rails --version 3.0.0

After you have both rails 3 and ruby 1.9.2 up and running, install the sqlite gem again.

gem install sqlite3-ruby

Now you should have a fully functional rails 3 + ruby 1.9.2 development environment! You can verify this by doing a simple 'ruby -v' and 'rails -v' from the command line.