14 Mar 2009

Running Rails 'on' Windows

I have been developing a Rails app on my aging Windows 2000 desktop PC since 2006. Luckily this PC has been trouble-free, so only ever had to get Ruby and Rails installed and working once.

Recently I decided that I should really move off an operating system that is nearly a decade old, and jump head-first into the modern world.

I dusted off my 7 year old Windows XP CD and popped it into my computer.

With my fresh new computer, I had a number of unsuccesful attempts at getting Rails working. I tried the Ruby One-Click Installer, but had a few problems when I updated to the latest version of Gems.

After some random searching I happened upon a great answer over at StackOverflow. The suggestion was to run Rails on a linux virtual machine. So that's what I did ...

1. Installed VirtualBox 2.1.4

2. Installed virtual machine Ubuntu Server 8.10
This is pretty easy, you just download the ISO from the Ubuntu site, in VirtualBox you create a new machine, and point it at the ISO.

3. Install Ruby & Rails
This was trouble free, I just followed the steps of this screencast over at O'Reilly Blogs.

At this point I made a decision that I would continue to do my actual coding in Windows and with an IDE (shhh, don't tell anybody or I'll get kicked out of the Rails community). I had previously used Eclipse with Ruby Development Tools and Subclipse plugins. This had served me well, but I recently had the opportunity to try NetBeans and liked it, so decided to go with this.

This meant the next stage was to have some sort of common file area between the Host and the Virtual Machine. I could of setup Samba on Ubuntu, but VirtualBox provides the feature of Shared Folders, which allows the guest operating systems access to folders on the Host.

4a. Setup Shared Folders
(a little bit of pain, more details to follow)

4b. Installed the VirtualBox Guest Additons in the the Ubuntu Server.
(a little bit of pain, more details to follow)

5. Configured port forwarding
There are number of networking options with VirtualBox, the default is NAT with the guests inside their own private network and VirtualBox doing NAT. This gives the guest easy access to the Internet, however it's services won't be accessible by the Host. The easiest option seems to be stick with NAT and configure port forwarding as per the instructions here.