More articles about Development

More articles about Ruby on Rails

Setting up Rails on Windows XP

By Christopher Haupt

Published April 23, 2008  |   9 comments

This guide walks you through setup instructions for preparing a Windows XP development machine to be used for general Ruby on Rails coding. This baseline setup is what we use for our LearningRails online course and the in-person seminars we offer.

You will end up with a development machine with the following baseline components:

  1. Ruby and all basic Ruby utilities
  2. Ruby Gems package manager
  3. Subversion client
  4. MySQL database client utilities and server
  5. Gems for Ruby on Rails, Capistrano, Mongrel, Mongrel Cluster, and MySQL
  6. SSH Terminal Program
  7. Programmer’s editor or IDE

Note: In the command sequences we illustrate here, command line prompts are shown as C:\>.

Prerequisites

This guide assumes you have a Windows computer running the current Windows XP operating system with up-to-date service patches applied (SP2 or higher). It also assumes you have not set up alternate Ruby on Rails tools prior to running through this guide. If you have, then small adjustments may be required as you walk through the following instructions.

You will need to have access to an Internet connection to complete various download steps.

You will need to have administrator access to your computer to complete this guide. Some of the Windows installers may ask you for your password.

The Recipe

Follow this recipe in sequence. If you have previously installed a particular component, you can usually skip the associated step.

Ruby and Ruby Utilities (irb, ri, rdoc)

The One-Click Ruby Installer does a lot of work for you by installing Ruby, Ruby Gems Package Manager, Rake, all of the other standard Ruby tools, and even the open source SciTE programmer’s editor. Additionally, the installer configures the command line interface path information, so the Ruby tools are ready to use in the Command Prompt program.

Download the latest installer (1.8.6 r26 as of this writing) and double click on it to get started.

Select all of the default settings and let the installer complete its work. Once done, open a Command Prompt (aka DOS Command Line) window by selecting the Start menu, then the Run… menu item, and then typing cmd and pressing return.

You can check that Ruby is installed by typing the command:

    C:\> ruby -v
    ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

You should seem similar responses. If you get an unrecognized command error, try closing your Command Prompt window and opening another one.

Ruby Gems Package Manager

You next need to install the latest version of gem.

Check the version that gets installed:

    C:\> gem -v
    0.9.4

You need 1.0.1 or newer. If you have an older version, you can update with the command line: gem update --system.

Installing a Subversion client

Subversion will be used to access your source code repository during development and deployments. You will need a current version of the Subversion command line client and you can use the official Windows installers on subversion.tigris.org.

Download the latest “Windows installer with the basic win32 binaries” option on the site. Double click the setup program and select the default options.

Once the installer is done, open a new Command Prompt window and check the installation:

    C:\> svn --version
    svn, version 1.4.6 (r28521)
       compiled Dec 20 2007, 16:33:06
    ...

Installing MySQL via the Offical MySQL Installer

You will be installing MySQL via the official Windows Essentials installer from MySQL.com. This installer handles all of the setup steps for you. After downloading the community edition (open source) Windows Essentials setup program, double click it to start:

Select the default (“Typical”) settings and location and let the program install itself. After it completes, a few ads will be shown, then a final dialog allowing you to configure the MySQL server. Make sure the check-box is selected and press “Finish”.

The “MySQL Server Instance Configuration Wizard” will run next. Choose the “Detailed Configuration” option and select all of the default choices. Doing so will configure the database to be running with settings best designed for a developer’s computer. When you get to the dialog offering the “Include Bin Directory in Windows PATH” option, we suggest you select it. If you don’t choose this option, you will need to manually set up your path so the “Command Prompt” program has easy access to MySQL client programs.

You will also be presented with a dialog to set a root password. If you are going to be working locally and aren’t worried about security, you can deselect “Modify Security Settings” and have a blank root password. We strongly suggest you set a password to be safe.

You can confirm that MySQL is running by trying to fire it up in the Command Prompt program:

    C:\> mysql -p -u root
    Enter password: ****
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1
    Server version: 5.0.51a-community-nt MySQL Community Edition (GPL)

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> exit

When you reboot your computer, MySQL will start automatically in the future.

Gems

While the One-Click Ruby installer added some common Windows oriented gems for you, you still need the Ruby on Rails gems and the gems used in the LearningRails course. Install them with the command:

    C:\> gem install rails capistrano mongrel mongrel_cluster

All installed gems (including Ruby on Rails and its dependencies, Capistrano, Mongrel, and Mongrel_Cluster) will get installed at their latest versions.

The MySQL adapter gem needs to be installed next.

    C:\> gem install mysql

Once the command completes, you should be all set with the baseline gems you will need for the LearningRails courses.

SSH Terminal Program

In deployment environments where your production or other remote servers are running a Unix-derived operating system, you will want to log in to those machines using the SSH protocol. A good Windows SSH terminal program is PuTTY. Download the complete Windows installer and double click to let it run.

You can select all of the default options. Once the installer finishes, you are ready to login to your remote machines.

Code Editing Tools

While you can get by with using a plain text editor like Notepad you will have much higher productivity if you use a programming editor that is highly tuned to Ruby on Rails development. The One-Click Ruby installer automatically installed the SciTE programmer’s editor. SciTE is ok for basic tasks with one or two files, but we recommend trying some of the other programs below.

We use the commercial TextMate programmer’s editor for much of our day to day work on the Macintosh. TextMate is highly extensible through a collection of community supplied “bundles”. There is a Windows “look-a-like/port” called the E Text Editor that looks promising and includes much of the functionality found on the Mac. Even better, it is supposed to be compatible with TextMate bundles, so as functionality improves for one platform, it should become available on the other. There is a trial version available if you want to test it out.

There are a variety of good open source or free programmer editors available too. On the open source side you can find ports of vim and emacs, both of which have add-ons to create a full featured Ruby and Rails development tool set. jEdit is a very extensible open source editor written in Java that has a decent Ruby programming plugin set.

Whatever editor you choose, be certain that it provides easy navigation among a large number of open files. Working with Rails applications generally involves dealing with a lot of small files, and that process needs to be efficient.

If you prefer an all-in-one tool, you should look at one of several integrated development environments that exist for Ruby. We use Netbeans in our LearningRails courses, but you should check out the numerous other options listed at BuildingWebApps.com.


Add your comment on this article






Reader comments on this article

From: Christopher Haupt       Date: 05/17/08 01:01 AM

Subject: RE: Path Problems

[jose] If you set your path up in the system environment preferences, they'll stick around. Go to Start,then right click on My Computer, select Properties, select Advanced, Environment Variables, and in the bottom of that dialog, find System Variables, and select Path and press Edit. Add your complete paths here: e.g. C:\ruby\bin. Be sure to separate each path with a semi-colon.

From: Jose       Date: 05/16/08 09:21 PM

Subject: Path problems in windows XP

Thanks for the clear up-to-date instructions. The best I have seen so far... But, I have a problem. PROBLEM: For some reason my windows XP erases all directory paths as soon as I restart (e.g. ruby\bin\ and mysql\...\bin). Including mysql and ruby paths. Is there a file I can run that would set all the paths each time my system starts? Or is there a way to configure my windows XP so the directory paths are kept?. Also i noticed that each time I set a new path manually, all previous paths are erased. As you can imagine, I am unable to work like this. Please help! this is very frustrating...

From: Jeff       Date: 05/09/08 11:11 AM

Subject: Instant Rails?

I've found Instant Rails (http://instantrails.rubyforge.org) to be very easy to set up. It's Ruby, Rails, Apache, MySQL, and a bunch of other stuff all in one .zip file. Just unpack and run.

From: Christopher Haupt       Date: 05/06/08 09:09 AM

Subject: RE: IntelliJ Rails Plugin

I don't have a current copy of IntelliJ, so haven't evaluated the Ruby/Rails plugin. From their site, it looks interesting. On Windows, I've been using the TextMate "port": E TextEditor (http://www.e-texteditor.com/) as well as Netbeans 6.1.

From: Elopez       Date: 05/05/08 04:04 AM

Subject: thx Christopher

Thank you Christopher, your steps worked perfect for the offline machines, actually I tried both, I have a desktop with win xp, and a laptop with windows vista,I downloaded the gems for vista just to try it out. It is so many gems to download that sounds interesting by their names. What do you think about intellij plugin for rails?

From: Christopher Haupt       Date: 04/29/08 10:10 AM

Subject: RE: Setting up when you don't have an Internet Connection

[Elopez] Yes, you can install on a disconnected machine. If your machines are the same architecture, you can grab your local gem cache (C:\ruby\lib\ruby\gems\1.8\cache on my machine). You can also download gems manually from places like RubyForge.org, or use the command "gem fetch". There are more complicated things you can do (including setting up local gem repositories and gem servers, but we'll skip that). Once you have the gem files local and transfered to your offline machine, move into that directory and use "gem install gemname --local" where gemname is the gem(s) you wish to install.

From: Elopez       Date: 04/29/08 05:05 AM

Subject: setting up when you dont have internet connection

Hi, Great article thank you guys for putting time to do this series that I am sure will help a lot of new rails programmers like me. I want to ask you is there a way to download the gems and install them in another machine (laptop) that does have internet connection.

From:        Date: 04/20/08 04:16 PM

Subject: great article!

This is a great article and helped me a lot!

From: AnotherDave       Date: 04/07/08 01:13 PM

Subject: Setting up Rails on Windows XP

Following your instructions to the letter, and using the same versions of the same software, will not deliver a workable Rails system. The first try, the installer puked on XP's wonderful "Program Files" directory path. I don't suppose it gave you any trouble at all. Second try, the installed programs failed to configure themselves for my spaceless c:\programs directory. I suppose I'll get this all sorted out someday, but then I supposed that about ten other installation tutorials would work, too.