Thursday, March 4, 2010

Ruby on Rails setup on Windows

Most of the in Rails community uses Mac and or Linux to develop Ruby in Rails applications. So, it is difficult to find resources or help on how to setup Ruby on Rails on Windows. Unfortunately we do develop on Windows since we also work on .Net application and cannot afford to have both environment.

Recently, I had to get a new laptop that came with Windows 7 (64-bit) and had to go through the pain of setting up a Ruby on Rails environment from scratch. The biggest challenge I faced was with the gems that require native extensions, for example, "rcov." And, the rest were to do with 32-bit versus 64-bit. If you are on the same boat, here is what you need to do,

1. Install Ruby. Get the Ruby installer from They have done a great job of putting together a great installer for the versions you would (1.8.6, 1.8.7 and 1.9) probably want to use. I would recommend installing it under C:\Ruby (the default) directory to avoid any configuration changes in the later steps of setup.

2. Update "PATH." Make sure that your "PATH" environment variable includes the Ruby\bin directory.

3. Setup to build native extension. Get the development kit from RubyInstaller site in order to be able to build native extensions for gems that require it. You need to get the 7-zip, if you do not have it already. Extract the files where you have installed Ruby.

4. Setup Gems. Now you can follow the usual steps of installing Rails gems as well as other gems. Gem should be able to build native extension without any problem. If you are on Vista or Windows 7, you have to run gem command from command shell opened as "run as admin" (by right clicking the program even if you are an Admin). I did not know this. It is Microsoft's attempt at becoming Unix (emulating "sudo" command).

5. MySQL setup. If you are using MySQL, you want to get the 32-bit version even though you machine is 64-bit. This is because the "mysql" gem that is available already comes pre-compiled with 32-bit version. You may still run into an error (i.e., MySQL::Error: query: not connected: SHOW TABLES) while accessing your database. This is most probably you have a newer version of MySQL than the "mysql" gem was originally compiled with (MySQL 5.1 does not work well with Rails 2.2 and later). You would need to get this libmySQL.dll. You need to get the older version and put it in Ruby\bin directory. 

That is all. You should be good to go. Let me know if you still run into issues following these steps.
Update: I ran into issues with the 1.8.7 version. Something to do with GC. Siwtched to 1.8.6, and it is working fine. March 12, 2010

No comments:

Post a Comment