Install Ruby on Rails with MySQL on Ubuntu 12.04

I have start working with Ruby and Ruby on Rails. I have faced some problem to install Ruby and Ruby on rails development environment  in my ubuntu. For this I share my experience to install ruby on rails development environment in ubintu.

Ruby on Rails:

Ruby on Rails, often shortened to Rails, is an open source full-stack web application framework for the  Ruby programming language.It  is one of the most popular framework for developing web applications using Agile approach. Rails (Latest version : 3.2) is based MVC (Model View Framework).  Here I show step by step installation via RVM (Ruby Version Manager).  Although RVM is not strictly necessary but it’s strongly recommended – it will allow you to use multiple versions of Ruby, which may be be required in some cases.

step 1. Install dependencies:

First you have to install git.

Git Install command :

sudo apt-get install git

Install Curl : Curl is a command line tool to get a file from FTP/HTTP/HTTPS server. To install, open terminal and execute the command –

sudo apt-get install curl

step 2. Install RVM:

Here is RVM installation command :

bash -s stable < <(curl -s

Now, you might have to edit the bashrc file to load RVM in shell session. To do that type –

gedit ~/.bashrc

Now add the following line to the end and save the file

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Then reload the shell session using the command –

source ~/.bashrc

To test your  RVM installation type –

type rvm | head -1

After executing above command you should be getting this output –

rvm is a function

That’s All.. You’ve successfully installed the RVM. Next, you have to install few additional dependencies. To find out those programs type –

rvm requirements

Now install the additional packages recommended by RVM –

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

Installing Javascript Runtime

In newer version of Rails, you also need a Javascript runtime. Install nodejs –

sudo apt-get install nodejs

step 3. Install Ruby

Now all dependencies and RVM is installed on machine.It’s time to install the ruby version you want .

To install ruby (1.9.3) run this command –

rvm install 1.9.3

Then select the version, you want to use –

rvm use 1.9.3 --default

You can check about the ruby version currently being used, then type –

ruby -v

step 4. install Rails

Finally, you can install the rails gem using a simple command –

gem install rails

By default rails install with SQLite . To Install rails with MySQL run this command –

In order to install the mysql gem you could use-

gem install mysql2

That’s All. Now, create a sample application (just for testing) using Ruby on Rails.

rails new my_app -d mysql
bundle install
cd my_app
rails server

Then open your browser and type the following address (to see the application running) –

Resources for learning Ruby on Rails –

1. Agile Web Development with Rails (Pragmatic Programmers)
2. Ruby on Rails 3 Tutorial: Learn Rails by Example (Addison-Wesley Professional Ruby Series)
. Railscast
4. Screencasts
5. Rails for Zombies 

Happy Coding 🙂


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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s