Installing Ruby on Rails Ubuntu 12.04 LTS using RVM and Ruby 1.9.3

Ruby Rails is a Web application framework created in 2004 intended as a rapid development web framework that runs the Ruby programing language. The latest version of the Ruby is ‘Ruby 1.9.2‘ and was realised in August 2011, it brings many new features and bug fixeses. The most signifiant changes are Block local variables, An additional lambda syntax, Per-string character encodings are supported and a new New socket API (IPv6 support). You can find a great walkthrough of all the new features at Ruby Inside. coinciding with the release of Ruby 1.9 is the Rails 3.1 framework which requires Ruby 1.8.7 or higher. RubyonRails 3.1 brings many new features, most notably: jQuery as default, HTTP Streaming, a new assets pipeline powered by Sprockets 2.0. So this is all good stuff and I’m sure you want to be working with the latest version of Ruby and RubyonRails, especially if you setting up a new server.

Well if your using Ubuntu you can setup Ruby and RubyonRails quickly using the supplied repository’s, a good tutorial for this can be found here. However this is not recommended as the Ubuntu repositories are often out of date and if you install ruby or rails via the repository’s it can be pain to upgrade. So in this guide we are going to go through installing RVM (this allows you to install, change and upgrade the installed Ruby version), Ruby 1.9.2 and Rails 3.1. This Guide has been tested on Ubuntu 11.10 however it should work on all versions of Ubuntu later then Ubuntu 9.04.

First of all you’ll need to install some packages that Ruby, RVM and RubyOnRails will require later, the easiest way to do this is using the repositories so go to your terminal and type:

sudo apt-get update
sudo apt-get install build-essential git-core curl libmysqlclient18 nodejs

Now let’s install the latest version of RVM using curl:

sudo bash -s stable < <(curl -s
umask g+w
source /etc/profile.d/ 

Now you'll need to ask RVM if it needs any more programs and if so you'll need to install them to do this type:

rvm requirements

Two things could happen here if you see the following message saying you need to install 'rvm', ignore this it and restart your terminal, this should fix the problem.

The program 'rvm' is currently not installed.  You can install it by typing:
sudo apt-get install ruby-rvm

You should see something that looks like this after you restart your terminal:

This tells you which packages you need to install using apt-get, just copy and paste the apt-get section under "# For Ruby" and run using the sudo command, this should look something like this:

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

Now you just need to give the user account access to the rvm files, you do this with the following command substituting [user] for the user you wish to use

sudo chown -R [user]:[user] /usr/local/rvm

Before completing this step I would recomend restarting your console otherwise you may run into problems. Once you have installed all these packages its time to install Ruby 1.9.3 herself. The following command will install Ruby 1.9.3 using the rmv package. However this can take a few minutes (15 in my case) to install so I recommend getting a drink, or my favourite, a pizza 😆 .

rvm install 1.9.3

Once ruby is installed you should set Ruby 1.9.3 as your default Ruby version, to do this enter:

source "/usr/local/rvm/scripts/rvm"
rvm --default use 1.9.3

You can test that Ruby is installed correctly and running at version 1.9.2 by typing

ruby -v

This should output something like "ruby 1.9.2p290.." showing you that version 1.9.2p290 is installed and is now the default Ruby version.

The nice thing about RVM is you can use it to install any version of Ruby and switch between the versions your have installed, to do this just enter "rvm install [Version Number]" then "rvm --default use [Version Number", you can then use "rvm --default use" to change to any installed version.

Now that you have the latest version of ruby installed I’m sure you want to get the latest version of Rails installed, at the time of writing this tutorial that’s Rails 3.1. To install Rails we can use GEM which is installed along with RVM and Ruby, to install the latest version of Rails just type, (this can take also take a while):

gem install rails

And that’s it you have now installed RVM, Ruby 1.9.2 and Rails 3.1 on Ubuntu 11.10 configured to use sqlite3, you can now setup your new Rails package with

rails new [project name]

Just as a final note, If you want to use MySQL instead of sqlite3 you'll need to enter the following

sudo apt-get install mysql-server
gem install mysql2
rails new [project name] -d mysql

, , , , , , , , , , , ,

Comments are closed.