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
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:
- Install VirtualBox
- 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)
- Make sure the system is up-to-date (it won't be). Let update manager run & reboot
- Install Virtual Box additions & reboot
- 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
- Ruby Enterprise Edition (cause this is what I run on my production server)
wget -c http://rubyforge.org/frs/download.php/66162/ruby-enterprise-1.8.7-2009.10.tar.gz
tar xzvf ruby-enterprise-1.8.7-2009.10.tar.gz
- Add Ruby Enterprise Edition bin path to "secure path" for sudo
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
- Install gmate, which makes gEdit behave like TextMate. Instructions are on the gmate github page.
- Make gem not install rdoc and ri by default.
echo "gem: --no-rdoc --no-ri" >> ~/.gemrc
- Install Rails, Sqlite, ZenTest, RSpec, Cucumber, & Factory Girl
sudo gem i rails sqlite3-ruby ZenTest rspec cucumber factory_girl
- 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:
- git-prompt, bash prompt with GIT, SVN and HG modules
git clone git://github.com/lvv/git-prompt.git && echo ". ~/git-prompt/git-prompt.sh" >> ~/.profile
- Autotest/Autospec notifications to Ubuntu system notifications (similar to Growl on OS X)
sudo gem i test_notifier && echo "require 'test_notifier/autotest'" >> ~/.autotest
- Sounds for Autotest events - http://www.fozworks.com/2007/7/28/autotest-sound-effects
sudo apt-get install mpg321 && wget -c http://www.fozworks.com/static/autotest-sound-1_2.zip && gunzip autotest-sound-1_2.zip && echo "require '~/autotest/sound/sound.rb'" >> ~/.autotest && echo "Autotest::Sound.sound_path = '~/autotest/sound/sound_fx/'" >> ~/.autotest