>FreeBSD + VirtualBox + RoR = nice, easy development environment :-D


So the new St. Noble security intern, Matt, has a hard-on for FreeBSD and has been trying to convince me to use it. Though I like to give him flak about it, I do actually enjoy the simplicity that it has to offer, and the delightful lack of a GUI – call me old-fashioned 🙂 [no, really, I do actually love a nice simple text interface, especially when I’m coding. Visual Studio, Eclipse, all those IDE’s are nice and all with their integrated file management, library browsers and auto-completion modules but when I code rails, I like using a simple text editor with nothing but the most basic syntax highlighting]  
I’ve found that, amongst other things, FreeBSD is great to use as a lightweight Ruby on Rails development environment, especially when combined with VirtualBox. If you own an IronKey, you can set up PortableVirtualBox and get it up and running quite easily.
Anyway, this is a simple guide to setting FreeBSD as your development environment. It’s not very in-depth, but I hope it will provide you enough tips and tricks to set yourself up without committing harakiri or throwing your machine out the window…
When you’re asked to do the partitioning, start by using auto-partition; take note of the different sizes, then adjust your swap space so that you can do a bit more swapping – I would recommend 1 GB instead of the de-facto standard. Choose a development installation on FreeBSD, and install the ports collection. Apart from that, follow the wizard. Pretty simple, huh?
I would recommend setting up sudo, but that’s not 100% necessary since your box is effectively sectioned off from all other computers. If you want to do that, then run ‘pkg_add -r sudo’. Remember to edit your /etc/sudoers file and add your regular username, and optionally prevent root from logging in via SSH by editing your /etc/ssh/sshd_config file.
VirtualBox setup:

Use a basic FreeBSD VM template, with two virtual NIC’s: set your first NIC up to be on the host-only network, and your second NIC to be on the NAT network. This allows you (and only you) to connect to your dev environment via SSH or web whilst providing the VM with a means to access the ‘net (especially practical if you’re consuming web services).

SSH and bash

By default, freeBSD uses csh. I’ve tried using tcsh instead, doesn’t seem to work for me; bash, on the other hand, works fine.  To install that, execute ‘pkg_add -r bash’ and wait until it’s installed. You can run it manually thereafter by executing ‘bash’ whether you’re at the console or remotely logged in via SSH. Ideally, though, you’d probably want your shell to be bash as soon as you start, right? Here’s the command to do that: ‘chsh -s /usr/local/bin/bash username‘, where /usr/local/bin/bash is the path to bash (so before executing the command, be sure to run ‘which bash’ to double-check the path) and username is your actual username. You must then edit your /etc/passwd file and substitute your shell for /usr/local/bin/bash – it’s the last field on the line with your username on it. You must both execute the chsh command and edit the passwd file in order for the switch to work! Kudos to vivek for the nice, easy tutorial that I didn’t read completely the first time like an idiot. If you follow it to the letter, this will work for your console, SSH, and will allow you to use SCP (there’s another way to set up bash on SSH, and that’s to use the ForceCommand directive in sshd_config – but that messes with your ability to use SCP).

Ruby, Rubygems, and Rails

No way around it – you’ve gotta compile the sucker; everything you need should be accessible via http://rubyonrails.org/download. Shouldn’t be too hard though: uncompress the tarball, run the usual ‘./configure; make; make install’. Download the rubygems tarball and install it using ‘ruby setup.rb’. Finally, run ‘gem install rails’.

Nano: syntax highlighting

A final note: if you are a fan of nano like me and you would like syntax highlighting, you can create a .nanorc file in your home folder and use the following example as a starting point: http://code.google.com/p/nanosyntax/source/browse/trunk/syntax-nanorc/ruby.nanorc