Setting up solid Ruby on Rails developer box based on Windows can be tedious task. More so than on other platforms, because vanilla Windows is meant for end user and lacks proper development tools that exist on other platforms. But fear not, there are many good people out there that have jumped through multitude of hoops to get different parts of the ecosystem working. All that remains is to build a solid foundation for developmer from them.
1. Ruby Installer
Of course the first and foremost brick in the foundation is RubyInstaller.org which is the easiest way to get Ruby working on Windows machine.
Just head over to the site and download the latest installer release (which at the time of writing is Ruby 1.9.3-p125) and run it.
After agreeing to the license terms, RubyInstaller prompts you with some options. I think it a good idea to put Ruby on the path and also associate
.rbw files with Ruby:
Go ahead and finish the install.
Some Ruby gems need to compile native code and in order to do so, they need some additional development tools which are missing in default Windows. Fortunately RubyInstaller has packaged them in a handy extension you can download from their download page under the “Development Kit” header.
Just unpack into some folder of your choosing, e.g.
C:DevKit (BTW, the package itself doesn’t contain a parent folder, so point it to an empty or non-existant folder) and navigate your
command prompt to that folder. Based on the DevKit manual, the following is needed to install it:
ruby dk.rb init
This will generate a
config.yml file which you could use to configure multiple rubies, but for now we leave it as is. To install DevKit, just enter:
ruby dk.rb install
By default Ruby Gem command installs documentation for every gem. I have found that Googling is much more convenient and faster than browsing local documentation and as generating docs from code often takes more time than installing the gem in the first place, I have come to disable the documentation from the start. To do so, open Notepad (we’ll come to install a better editor later on) and input:
gem: --no-ri --no-rdoc
Save the file under your Documents and Settings directory with a filename
.gitrc (yes, with a leading dot – that means hidden file in UNIX). E.g for me:
C:Documents and SettingsLaas.gemrc
I won’t even come to the argument whether version control is needed. It’s a must. Period.
For me (and a lot of folks out there) currently GIT is the best version control system – you can start using it without much effort and without even thinking about where to store the repository in the long run – it will all come in it’s own time.
For Windows users the easiest way to get GIT up and running is using msysGit. Head over to their Downloads page and download latest release (which at the time of writing is Git-1.7.9-preview20120201.exe).
Installing msysGit asks you a few questions. First come the install options and you could choose to check ‘Git GUI here’ (and maybe ‘Git Bash Here’, but we’ll change the terminal emulator later on so that won’t be as helpful):
Next two settings are of importance. First one chooses how Git is integrated to PATH and I think the golden middle is best:
And the last one changes how Git treats Windows line endings. Working with multi-platform programs (and Ruby on Rails is a good candidate for that) can be problematic, when developers don’t consider that Unix and Windows use different line endings (LF and CRLF respectfully). Git can automatically convert between the two and that is the default selection in msysGit. Change this only if you know you need to. Even if your editor already uses Unix endings, the first option won’t hurt.
Now you should have a working Git installation.
3. Console 2
Windows Command prompt is a pain to use. It has multiple shortcomings when it comes to developing and while some are harder to overcome (e.g copy-paste because Windows uses Ctrl-C to copy, which at the same time is used to terminate a running command), others are more easy. There are several alternatives to the default
cmd.exe, but I have found that the best is Console 2.
It is actually a wrapper to cmd.exe but it adds Tab support, easier copy-paste and whats best for Rails developer – flexible windows width, so that you can fit all those routes in the window.
Just head over to their site and download latest version and unpack it (I chose to put it under ‘Program Files’, but the location does not matter). For easier access, make a shortcut on your desktop.
For even better experience, we configure Console to use Git Bash we installed in the previous step. Open Console and navigate to
Edit > Settings > Tabs. There the Shell division has two options. First one points to the executable that is run as the command interpreter. Default empty value means ‘cmd.exe’, but we change it to Git bash. First use the file navigator option to find Git bash (in the ‘bin’ folder under Git installation directory) and then add two options to that line:
C:Program FilesGitbinbash.exe --login -i
Next, if you keep all your projects in one folder, set the startup directory to point to that folder.
All together you should see something like this:
If you now restart Console, you should see a bit different look (which you like, I hope).
As pormised, we now come to pick a good programmers editor. There are a lot of choices out there and I won’t come to claim any of them to be THE single best. Also, as many of the best editors are actually paid software, I won’t advertise any of them, but will only make a short list of them and point out a few things to notice.
Many of Rails developers are Mac users and many of them use TextMate as their editor, thus a lot of TextMate bundles exist to make developers life easier. It might be a good idea to start with one of those that support TextMate bundles.
Give a try of many of them to find your poison:
- Notepad++ – free and powerful editor
- jEdit – also free, but Java-based and cross-platform
- E Texteditor – paid app, but has the benefit of using TextMate bundles.
- Sublime Text 2 – paid app (currently in beta), also supports TextMate bundles, it’s cross-platform
- Komodo Edit – free IDE, cross-platform
- RubyMine – paid Ruby IDE, cross-platform
Which ever editor you choose, most definitely you need to configure it to your needs. At the bare minimum, you have to choose whether you use tabs or spaces and how many of them for indenting code lines.
To give you a head start, it seems to be convention in Ruby world to use 2 spaces instead of tabs – this is a good balance between readability and width for most Ruby projects and also makes it easy to share and edit Ruby code online (where tabs are not so easy to enter) or via email etc.
Last thing before firing off development would be to install Rails itself along with its dependencies. Open console and type the following commands.
gem install bundler
This installs fantastic Bundler gem to manage your apps gems for you.
gem install rails
And this installs Rails itself.
Now, off you go. Start developing Rails applications. Shue!