Sunday, August 29, 2010

Installing Rails 3 on Ubuntu 10.04 (Lucid)

This is mostly just for my purposes as it was not an easy task to get this to work. If it helps someone else, great!

Install GIT

Git needs to be installed in order to use RVM properly. Since the version of Git that is available through debian package is rather old, this is the process to get the latest version of git installed.
  1. Install build dependencies for git:
    $ sudo aptitude build-dep git-core
  2. Download the latest version of git (in this case 1.7.2):
    $ wget http://kernel.org/pub/software/scm/git/git-1.7.2.tar.gz
  3. Extract archive and change to the extracted directory:
    $ tar xvzf git-1.7.2.tar.gz && cd git-1.7.2
  4. Build git from source:
    $ ./configure && make && sudo make install
  5. Verify the installation of git:
    $ git --version
  6. Assuming everything worked, you can now remove the source:
    $ cd ../;rm -rf git-1.7.2 git-1.7.2.tar.gz

Install RVM

Ruby Version Manager (RVM) is the easiest way to install and switch between different versions of Ruby. While apt-get does tend to be easier on Ubuntu, you don’t necessarily get the latest version, which is what I wanted for Rails 3.
  1. Install curl:
    $ sudo aptitude install curl
  2. Install Ruby build dependencies:
    $ sudo aptitude build-dep ruby
  3. Install RVM:
    $ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
  4. Add the following line to your .bashrc to install RVM as a function:
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
  5. Restart your bash terminal and check that RVM is indeed a function:
    $ type rvm | head -n1
    rvm is a function
  6. Check to see what other dependencies you may need (Update: I got this list of dependencies from $ rvm notes, it varies from host to host and which interpreter variants you intend to install):
    $ sudo aptitude install bison build-essential zlib1g zlib1g-dev openssl libssl-dev libreadline5 libreadline5-dev libreadline6-dev libxml2-dev patch subversion autoconf libsqlite3-0 libsqlite-dev sqlite3
  7. Install Ruby version 1.8.7 first:
    $ rvm install 1.8.7
  8. Use Ruby 1.8.7:
    $ rvm use 1.8.7
  9. Install latest version of Ruby (in this case 1.9.2):
    $ rvm install 1.9.2
  10. Use latest Ruby and set as default:
    $ rvm use 1.9.2; rvm --default 1.9.2
  11. Check that Ruby and RubyGems are the proper versions (1.9.2/1.3.7):
    $ ruby -v
    ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
    $ gem --version
    1.3.7
  12. Install Rails 3 (Update 2: Shortly after posting this, Rails 3 was officially released, so the --pre option is no longer necessary):
    $ gem install rails --pre 
After the last step you should have a copy of  Ruby 1.9.2 with the Rails 3 gem installed. Also note that I’m using the user-level install of RVM. It does not require root and is not available to other users on the system. If you need those things, you might want to check out RVM’s install procedures.