Tuesday, 24 April 2012

Ruby on Rails environment setup on linux

I have been looking around for a quite long time to find all the Ruby on Rails environment setup instructions for linux on a single page, so finally i decided to write a blog where all the things from Netbeans to RVM gemsets are available under the same hood.

In this tutorial, we are going to setup:

  1. Appache2 server
  2. MySql
  3. Phpmyadmin
  4. RVM setup
  5. Installing Ruby
  6. Creating Gemset
  7. Installing Rails and some other gems
  8. Netbeens Installations


I have been using ubuntu 10.04, but will equally valid for higher versions up till 11.10.

Lets Start

Open the terminal, you can find it in, Applications -> Accessories -> Terminal
Copy each and every command from the rest of the page and paste it in the terminal, sequentially. In most of the commands, i have been using the word "sudo" which is require to install the desired packages with admin user rights.

Installing Appache2 server


:~$ sudo apt-get install apache2
:~$ sudo /etc/init.d/apache2 restart

The first command will install the Appache2 server and second command will restart the server again to   work it normally. This command is not essential but we should do it being on safer side.

Installing MySql


:~$ sudo apt-get install mysql-server
:~$ sudo /etc/init.d/mysql restart
:~$ sudo apt-get install libmysqlclient-dev

Now, the things are going to be self explanatory. The first command will install the server and the following one will restart it.

To check the status of the MySql, issue the following command

:~$ sudo netstat -tap | grep mysql

Installing Phpmyadmin


:~$ sudo apt-get install phpmyadmin

Now open the following file in any of your favorite text editor and put the following line. I will use vim.
Include /etc/phpmyadmin/apache.conf

:~$ vim /etc/apache2/apache2.conf

Now, open you favorite browser and access the local host by hitting the url "localhost/phpmyadmin" If you get some error then try installing the phpmyadmin by using the following command and during installations, select the "apache2" from the option list and continue installations.

:~$ sudo dpkg-reconfigure -plow phpmyadmin

Now, hit again the localhost, this time it will be working hopefully.

RVM setup

Rvm is Ruby Version Management tool which widely used to setup different RoR environments on the same machine and allowing you to switch between different environments, depending upon projects, very easily. To read more about RVM, you can visit the this site where you can find much more stuff related to rvm. 

RVM require has some dependencies issues, so you need to first install some of the supporting libraries to install rvm and work it properly.

:~$ sudo apt-get install build-essential
:~$ sudo apt-get install zlib1g-dev libreadline-dev libssl-dev libxml2-dev

There are some prerequisites which you can easily install by issuing the following commands.

:~$ sudo apt-get install curl git-core

Now install rvm:

:~$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

Now, close your shell/terminal and open a new one and run the following command.