Setting up Ubuntu 9.10 for Ruby and Rails Development in VirtualBox on Windows

I now believe that if you're serious about creating Rails apps, you aren't doing it on Windows. Or, you are a masochist.

That’s a quote from me. I’m done trying to do serious Ruby & Rails development on Windows. As of January 1st, 2010, I have not found a Ruby implementation on Windows that is fast enough to support the TDD/BDD workflow that Corey Haines exhibits in his Number to LCD code kata. On top of that, I wasted 2 days on trying to get Selenium and Cucumber to work together in Windows. I was venting about this on Twitter when Cory Foy made a suggestion:

@hotgazpacho You know, I don't know why you don't just run a VM with Linux on it for Rails dev. That's what I have on my Windows box.

I didn’t know why either. My first concern was memory consumption (my personal notebook only has 2 GB of RAM in it), but both Cory and Robert Dempsey allayed my fears:

@hotgazpacho 2GB should be plenty. The Linux VM should only need 512. Would help to run the VM on an external drive if you've got one

@cory_foy @hotgazpacho I run linux ubuntu vm's (vmware) on my MBP and 512 is more than enough if you don't use a heavy IDE. Runs very well

So, I went ahead and set up Ubuntu 9.10 in a VirtualBox virtual machine (VirtualBox is a free virtualization product from Sun, similar to VMWare Workstation or Microsoft Virtual PC). The results were astounding! On a Rails app I was working on, all the RSpec examples and Cucumber features ran in less than the time it took for the MingW Ruby interpreter to start up. WOW! We’re talking orders of magnitude faster, and all in less memory than it takes to boot Windows. I’m sold.

Here’s how I set up the VM:

  1. Install VirtualBox
  2. Create a new VB VM for Ubuntu
    The Ubuntu Community wiki has pretty good documentation (for Ubuntu host, but UI is pretty much identical on Windows)
  3. Make sure the system is up-to-date (it won't be). Let update manager run & reboot
  4. Install Virtual Box additions & reboot
  5. Install pre-requirements for building stuff (note: I may be missing some stuff. If I am, Ruby Enterprise Edition installer will let you know and tell you what is missing):

    sudo apt-get install build-essential libpcre3 libxml2-dev libxslt1-dev sqlite3 libsqlite3-dev –y
  6. Ruby Enterprise Edition (cause this is what I run on my production server)

    wget -c
    tar xzvf ruby-enterprise-1.8.7-2009.10.tar.gz
    sudo ./ruby-enterprise-1.8.7-2009.10/installer

  7. Add Ruby Enterprise Edition bin path to "secure path" for sudo

    sudo visudo
    Change line starting with Defaults to the following:
    Defaults env_reset, secure_path=/opt/ruby-enterprise-1.8.7-2009.10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  8. Install gmate, which makes gEdit behave like TextMate. Instructions are on the gmate github page.
  9. Make gem not install rdoc and ri by default.

    echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
  10. Install Rails, Sqlite, ZenTest, RSpec, Cucumber, & Factory Girl

    sudo gem i rails sqlite3-ruby ZenTest rspec cucumber factory_girl
  11. Make cucumber feature running part of autospec runs

    echo "export AUTOFEATURE=true" >> ~/.profile

One Minor Problem…

There’s only one minor problem with this whole setup. Cory Foy articulated it best:

@hotgazpacho The problem is now you'll /really/ not be happy doing Rails on Windows. Ever. :)

This is a problem I can live with :)

For some additional fun…

…you might want to install the following:

  1. git-prompt, bash prompt with GIT, SVN and HG modules

    git clone git:// && echo ". ~/git-prompt/" >> ~/.profile
  2. Autotest/Autospec notifications to Ubuntu system notifications (similar to Growl on OS X)

    sudo gem i test_notifier && echo "require 'test_notifier/autotest'" >> ~/.autotest
  3. Sounds for Autotest events -

    sudo apt-get install mpg321 && wget -c && gunzip && echo "require '~/autotest/sound/sound.rb'" >> ~/.autotest && echo "Autotest::Sound.sound_path = '~/autotest/sound/sound_fx/'" >> ~/.autotest


comments powered by Disqus