Last time, I installed Rails on the Debian box and had some trouble, but I got through it. This time, I’m going to install Rails on the Windows box. This is my laptop that I have with me most often, so I need to develop from it, too.
Installing Ruby and RubyGems
To begin, I need Ruby on the machine, and luckily there is a Windows installer available. The RubyInstaller project is:
…a self-contained Windows-based installer that includes the Ruby language, an execution environment, important documentation, and more.
That’s handy. I download the latest RubyInstaller from here and run it. I make sure to check Add Ruby executables to your PATH so I can use ruby and gem from the command line.
When it finishes, I open a command prompt to make sure it installed correctly.
C:\Users\Miller>ruby --version ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
RubyInstaller also installs RubyGems automatically, but it’s an older version.
C:\Users\Miller>gem --version 1.7.2
I update to the latest version using the gem update --system command.
C:\Users\Miller>gem update --system Updating rubygems-update ...snip... C:\Users\Miller>gem --version 1.8.10
Installing Rails
The easiest way to install Rails is with RubyGems.
C:\Users\Miller>gem install rails
...snip...
Fetching: json-1.6.1.gem (100%)
ERROR: Error installing rails:
The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'Uh oh. I didn’t notice that in the documentation.
It turns out that some of the gems are actually written in C and only distribute the source code. When you install a gem, the system must compile the source into a binary, which is then installed. This requires the UNIX-based development tools for the compilation, but these aren’t normally on a Windows box. The Ruby DevKit is a port of all the necessary tools required to build the C extensions from source.
So, off I go to the RubyInstaller Download page to grab the DevKit and install it in the C:\Ruby directory.
Following the DevKit instructions, I run the installation.
C:\Ruby\DevKit>ruby dk.rb init [INFO] found RubyInstaller v1.9.2 at C:/Ruby/v192 Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to all of the installed Rubies you want enhanced by the DevKit. C:\Ruby\DevKit>ruby dk.rb install [INFO] Updating convenience notice gem override for 'C:/Ruby/v192' [INFO] Installing 'C:/Ruby/v192/lib/ruby/site_ruby/devkit.rb'
I cross my fingers and try to install rails again.
C:\Ruby\DevKit>gem install rails Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ...snip... Successfully installed rails-3.1.1 5 gems installed ...snip... C:\Users\Miller>rails --version Rails 3.1.1
It works. I’m almost done for now, but I want to ensure the installation worked.
Testing
I’ve installed Rails, but I need to make sure everything works before I quit for the day.
C:\Users\Miller>rails new testapp
create
...snip...
run bundle install
which: no sudo in (MY REALLY LONG PATH ENVIRONMENT VARIABLE HERE)
Fetching source index for http://rubygems.org/
..snip...
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.Clearly, Bundler is trying to find sudo, which doesn’t exist on Windows. However, it did tell me it was successful, so I’ll try to start the development server.
C:\Users\Miller\testapp>rails server => Booting WEBrick => Rails 3.1.1 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-10-20 01:13:38] INFO WEBrick 1.3.1 [2011-10-20 01:13:38] INFO ruby 1.9.2 (2011-07-09) [i386-mingw32] [2011-10-20 01:13:38] INFO WEBrick::HTTPServer#start: pid=1116 port=3000
Success! When I send my browser to http://localhost:3000/ I see the default Rails Welcome aboard page. Hopefully that Bundler/sudo issue doesn’t come back to bite me in the ass later.
That’s enough for now. If you have any comments or suggestions, please leave a comment. Next time, I’ll create my Rails project and learn a little about the environment. It’ll be fun, so come back and check it out!

