How To Install Ruby on Rails on Ubuntu using RVM

Why RVM (and not native ruby packages)

There may be debate, but I have found that for a development system, it is increadibly easy to use rvm, with it’s different ruby versions, different gemsets per project.


Install RVM

Getting your Linux environment set up for RVM is the hardest part of installing RVM itself. If you’re unfamiliar with the process of compiling Ruby from source, you can get a little lost. Thankfully, distributions like Ubuntu make things pretty easy.These instructions are written on Ubuntu.
For the most part, they will apply to any Debian or Ubuntu based distribution.First and foremost you need the C compiler and the Make utility. These are usually bundled together with some other tools and behind the scenes magic in a package called build-essential. So this is the first package that should be installed.

$ sudo apt-get install build-essential

In addition, RVM will also need curl to download files. This is also a simple apt-get.

$ sudo apt-get install curl

Next you’re going to need a few libraries and their development package counterparts. Two of these libraries are readline, which lets you edit lines of text in bash or IRB, and zlib, which Rubygems will need to function. Also included is OpenSSL and LibXML.

$ sudo apt-get install zlib1g-dev libreadline-dev libssl-dev libxml2-dev

Now that you’re all set up, install RVM itself. This is done via a shell script which you can download and run directly with a single command.

$  \curl -L | bash -s stable

Append the following line to your ~/.bashrc file.

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM

And then reload your bash environment (or close the terminal window and open a new one).

$ source ~/.bashrc

In later version of RVM, an rvm requirements command was added to give you more information about the build and run requirements for various rubies. You can see and peruse this list of requirements by running rvm requirements.

$ rvm requirements

It even gives you handy apt-get commands you can simply copy and paste.

Setup Ruby and Rails

You’ll probably want to install the MRI Ruby interpreter (the official Ruby interpreter, the one you’re probably already familiar with). To do that (after you installed the build dependencies, see the previous steps), it’s a simple rvm install 1.9.3. This will give you the MRI interpreter version 1.9.3 (the stable release at the time this article was written) at the latest patch level.

$ rvm install 1.9.3 

And that’s it. Remember to rvm use 1.9.3 before you start using Ruby and that’s it, Ruby is installed.

Install basic rails in this gemset.

$ gem install rails

Now make and use a gemset for rails 3.1

$ rvm gemset create rails31

$ rvm gemset use rails31

And that’s it, Ruby and Rails installed.

A list of  Ubuntu package dependencies for gem ‘mysql2’

$ sudo apt-get install mysql-client mysql-server libmysqlclient-dev

Hope you find this tutorial helpful. Feel free to ask questions! Don’t forget to like or to leave a comment if its really help you.


4 thoughts on “How To Install Ruby on Rails on Ubuntu using RVM”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s