Setting Up Rails Development Environment on Windows Vista/XP
There are different ways in which you might want to set up a complete development environment for Ruby on Rails on a Windows machine. I am going to cover how to setup Rails on a Windows machine using Ruby, RubyGems, Rails, Mongrel, MySQL, NetBeans and Subversion as part of the development stack. I will be using Windows Vista as the reference OS but most of the instructions work for Windows XP too.
- Installing Ruby: Download and install the latest final version of the Ruby installer(currently 1.8.6) from the rubyforge.net website: One-Click Ruby Installer for Windows
Leave all the default settings as they are and proceed with the installation wizard. It is important that you install Ruby in a path which doesn’t contain any spaces in it(the path c:\ruby selected in the wizard by default works fine).
After the installation is complete, confirm that the ruby commands are added to the system path. Start the Command Prompt(Start -> Accessories -> Command Prompt) and type the following command:C:\> ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
C:\> gem -v
If you get the “not recognized as an internal or external command” error, add the path to the ruby bin directory(e.g. c:\ruby\bin) to the system PATH environment variable(Control Panel -> System -> Advanced System Settings).
- Updating RubyGems:
The above installer also installs RubyGems package and SciTE editor as part of the “one-click” installation process. Unfortunately though, the installed version of RubyGems may be a bit old(~0.9.4), so run the following command to update it to the latest available version(currently 1.1.1):C:\> gem update ––system
C:\> gem -v
Note: Add “-p http://proxy:port” to all gem install commands if you are connecting to the Internet through a proxy.
- Installing Rails:
Now it is time to install the Rails package. Run the following command to install Rails as a ruby gem:C:\> gem install rails
C:\> rails -v
In future, whenever you want to update Rails to a newer version, simply run the following command:C:\> gem update rails
The basic Rails development environment is now installed on your system and you can skip the rest of the post if you are happy with WEBrick as the web server, SQLite as the database server and SciTE as the editor(or your favourite text editor/IDE already installed on your system). The following instructions cover installing an alternate web server called Mongrel; MySQL database server and its GUI tools; NetBeans IDE, Subversion and their integration.
- Installing Mongrel:
Installing the Rails gem also installs the WEBrick web server which is ideally suited for development purposes. Another much recommended web server for Rails development as well as production environment is the Mongrel web server. To install the Mongrel web server, run the following gem command:C:\> gem install mongrel
C:\> gem list mongrel
*** LOCAL GEMS ***
After installing Mongrel, Rails automatically starts the Mongrel instead of WEBrick web server when you run the Rails applications in development mode. (Refer to Mongrel documentation to know more about runing Rails applications under Mongrel in production mode.)
- Installing MySQL:
This step covers the installation of MySQL database server and its GUI tools. Skip this step if you want to use some other database server.
Download and install the MySQL 5 database server. You can safely accept all the default settings of the installation wizard. After MySQL database server is installed, you need to run its configuration wizard to configure the MySQL installation.
- If you are a Windows XP user, run the configuration wizard directly from Start -> MySQL -> MySQL Server 5.0 -> MySQL Server Instance Config Wizard.
- If you are a Windows Vista user, you first need to patch the configuration wizard before running it. Follow these instructions to patch the MySQL configuration executable using ResHack utility. Once that is done, you can run the configuration wizard from Start -> MySQL -> MySQL Server 5.0 -> MySQL Server Instance Config Wizard.
One important step during the configuration process is to select a root password(you will need to enter it in the database.yml configuration file of your Rails application).
- Installing Netbeans:
You can use your favourite text editor or IDE to code your Rails application. Two of the most popular, Free Rails IDEs are NetBeans and Eclipse. NetBeans in particular has shown great improvement in its support for Ruby programming language and the Rails framework. I am going to cover configuring Netbeans for developing applications with Rails, so feel free to skip this step if you want to go with some other IDE(Aptana, IntelliJ IDEA etc.).
Go to the download page of Netbeans IDE and download either the “Ruby” version(~29MB) or the “All” version(~219MB). (Ruby version supports only Ruby where as the All version supports Java, C++, etc. in addition to Ruby.)
Install NetBeans. Run it. When creating a new Rails project in NetBeans, remember to select “Ruby” as the default instead of the default “JRuby” and then select Mongrel as the web server.
For more information on developing Ruby on Rails applications using the NetBeans IDE, refer to the following links:
- Installing Subversion:
Go to the Subversion download page, scroll down to the Windows section and click the “Win32 packages built against Apache 2.2″ link and download and install the ‘basic win32 binaries’ package.
You can now work with the Rails applications stored in subversion repositories. You can also install and use TortoiseSVN which is a GUI subversion client that integrates very well with the Windows Explorer. I couldn’t find a way to integrated it with NetBeans though, so I install the subversion command line version to use with NetBeans even if I have TortoiseSVN installed on my system.
- Configuring Subversion in NetBeans:
Start the NetBeans IDE and go to Versioning -> Subversion -> Checkout. If you see a dialog box as shown in the screenshot below, it means subversion is properly installed and configured on your system. You can enter the repository details in the fields shown by the wizard, checkout a Rails application and work on it from the NetBeans IDE.
(If you see an error instead, then you need to either add the subversion bin directory to the system PATH variable or enter the path in the shown NetBeans configuration window.)
Now you can create/checkout rails applications, edit them and run them under Mongrel from within the NetBeans IDE. One crucial item missing from this development environment is an alternative, more powerful automated build tool CruiseControl, which can also be integrated with NetBeans. Perhaps a topic for another post. In the next post I will explain how to create a basic “Hello World” application in Rails using the above development tools.