Wednesday, August 17, 2011

Ruby on Rails Development Platform in Enterprise

Ruby on Rails is growing in enterprises in India, but they are still lagging with popular development platforms like Mac or linux. As it's difficult for them to afford Mac and they cannot use Linux based Operating Systems (OS) on host machines due to security constraints or to use some windows based apps. So I decided to use Virtual Machine on my Windows based Host System.

Now To use Ubuntu (Linux based OS) with above configuration, follow below steps-

1. Download and Install VMWare Player which is free for personal non-commercial use. VMware Player is only distributable with written permission from VMware. So don't share the exe/setup, download it separately.

3. Create a New Virtual Machine for Ubuntu using VMware Player. Just follow 'Next' Its simple. It takes default 512 MB of RAM but I did allocate 896 MB of RAM as I had 2 GB of RAM. (It might install required files.)

Now you have Ubuntu ready on your windows based system. To install Ruby and Rails using RVM please follow below steps-

1. To install RVM you need git. Run below command to install git-
ubuntu@ubuntu:~$ sudo apt-get install git
And then follow installation steps for RVM here.
OR
Run below command in terminal-

5. Set default versions of Ruby and Rails using rvm. I am using ruby-1.8.7-p352@rails_3 as I have installed ruby 1.8.7 and created gemset named as rails_3.
ubuntu@ubuntu:~$ rvm use --default ruby-1.8.7-p352@rails_3

6. Now you can install rails.
ubuntu@ubuntu:~$ gem install rails

You are ready with ruby and rails, Now you need database. You can simply install mysql or postgresql using apt-get install command or from ubuntu software center.

I wanted to use Oracle but I didn't install it on my ubuntu system (virtual machine) as it's running less than 1 GB RAM which is kind of minimum requirement for oracle database. And I have already installed Oracle XE on my host system so I am going to use it using Host IP address in my database.yml of rails app.

To use oracle I need to install ruby-oci8 and activerecord-oracle_enhanced-adapter gems.

2. If you are facing any issues to install gem ruby-oci8, you have to set path for LD_LIBRARY_PATH in your .bashrc. Eg: export LD_LIBRARY_PATH="/opt/oracle/instantclient_11_2"

Apart from these you have to install few required libraries and application like tortoisesvn, NetBeans(IDE) etc. Currently I am using Ubuntu just by using 896MB of RAM and it works fine.

Few things to remember while using this combination-

1. Increase RAM size allocated from 512MB, if you are going to use NetBeans as it takes bit lot memory.

2. Increase number of Processors to 2 if you have core 2 Duo, Default its set to only 1. It really helps.

3. From Virtual Machine Settings -> Hardware -> CD/DVD Device, dis-select 'Connect at power on' check box as you may not have CD-ROM available.

4. CTRL+G is used to enter into Virtual Machine and CTRL+ALT get out of it.
CTRL+ALT+DELETE call is taken by both Virtual Machine and host system. So make sure you will be using host system if you want to lock it.

6. If you want to have shared folder between host system and virtual system, refer the article here to update Virtual Machine Tools first and then you can simply add folders from Virtual Machine Settings -> Options -> Shared Folders. You will get them in /mnt/hgfs

Note: I was using a network where I was able to download all required software.

As Ankit has already said 'Loved it'. Just to let you know this is immensely helpful upto the extent that the specs which used to run for 5 mins on windows, they run in 18.25 secs! This should be now mandatory for people who are building web apps on RoR and still have to work on Windows OS.

I just faced one trouble (http://stackoverflow.com/questions/7271642/after-setting-up-rvm-and-ruby-187-getting-this-error-of-undefined-symbol-rb-dig), but later got an answer and resolved it