Monday, 8 September 2014

Configure Ubuntu 12.04 for Ruby On Rails development

What is "Ruby On Rails"?

Ruby is a programming language and rails is a software library that extends the Ruby programming language. David Heinemeier Hansson is creator of rails. He gave it the name "Ruby on Rails" though it is often just called "Rails."

Install Ruby with RVM

To make sure our all the package that we are going to install are upto date. We should run a quick update. Open terminal and type command:

sudo apt-get update

Once we have done with update. We will start installing RVM (Ruby Version Manager). RVM is a great tool to manage multiple versions of ruby on single machine.

In this blog we will going to use curl to install RVM.

If you don't have curl on your system, then type command:

sudo apt-get install curl

After you finish with curl. Install rvm using following command:

\curl -L | bash -s stable

After installation finished, load RVM. You may need to exit out of your terminal and start up a new one. To load RVM :

source ~/.rvm/scripts/rvm

RVM has some of its own dependancies that need to be installed. To automatically install them:

rvm requirements

You are done with rvm. Now installing ruby is easy.

rvm install ruby-2.x.x
rvm install ruby-1.9.x

And so on. Using specific version as default.

rvm install ruby-2.x.x --default

Sometime you may get following error:

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit for an example.

Answer for error is in error itself. go here and make desired changes and you are done.

Now next we makes sure that we have all the required components of Ruby on Rails. So we continue to install rubygems (By default RVM already installed gems for current version). 

rvm rubygems current

Once everything is set up, it is time to install Rails. 

gem install rails

This process may take a some time, be patient. Now we have Ruby On Rails on our machine.

For different requirement we need different database. So now we start with PostgreSQL setup. By default sqlite used as database in rails.


Install PostgreSQL:

To download Postgres and its helpful accompanying dependencies:

sudo apt-get install postgresql postgresql-contrib

You are done with postgres installation.

Create database user(Role):

Postgres uses the concept of roles to distinguish the variety of users that can connect to a database. When it is first installed on a server, the default postgres user is actual named “postgres”. 

To create custom user, first switch into the default user:

sudo su – postgres

Now create new role(user) in PostgreSQL system :


It will propmpt you as follow :

Enter name of role to add: newuser
Shall the new role be a superuser? (y/n) y

If you want to set password for newly created Role(User) then command should be:

createuser --pwprompt

Install MySQL:

installtion of MySQL on ubuntu is pretty simple. Open command promt and type :

sudo apt-get install mysql-server

During installation process MySQL will ask you to set a root password. Set your root password and you are done.

Now we have fully configured machine with RVM, PostgreSQL and MySQL for rails development.

1 comment: