Installing Rails 3 on a fresh Ubuntu 12.04

How many times have you wanted to install rails 3 on a system and you ended up in dependency hell? I know I have. Life was simpler with Rails 1 and 2. You could use ruby 1.8.7 and all was good. Now you should use 1.9.3. On ubuntu systems it is confusing to install ruby 1.9.3 because the package is called ruby1.9.1. If you install the apt package rubygems, Ubuntu will install ruby 1.8.7, just the opposite of what you want to happen. I’ve run into this issue enough times to document a fool proof way to get rails 3 onto your Ubuntu system.

 

sudo apt-get update
sudo apt-get build-essential # this is needed for installing rubygems
sudo apt-get install ruby1.9.1 ruby1.9.1-dev 
sudo apt-get install libyaml-ruby 
sudo apt-get install libsqlite3-dev # needed for gem sqlite3
# download rubygems ( I used 1.8.25) 
tar xzvf rubygems-1.8.25.tgz
cd rubygems-1.8.25/
sudo ruby setup.rb
sudo gem install rails
sudo gem install sqlite3
sudo apt-get install nodejs # Or one of the other acceptable javascript runtimes from https://github.com/sstephenson/execjs
sudo apt-get install libmysqlclient-dev # if you want to use mysql, do these lines as well
sudo gem install mysql2
sudo gem install activerecord-mysql2-adapter

If you read the docs on installing RubyGems you’ll notice they recommend the apt-get packages libyaml-ruby and libzlib-ruby. I installed the first one but the second will already be installed with the above list. With this arrangement you will only have ruby 1.9.3p0 installed and your rails will be 3.2.13

 

spustay@roar:~$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
spustay@roar:~$ rails -v
Rails 3.2.13

I hope you can use this list, I reference it when I need to.

Leave a Reply

Your email address will not be published. Required fields are marked *