Learning Rails: Installing Rails, Part 2 – Windows

Table of Contents

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

I update to the latest version using the gem update --system command.

C:\Users\Miller>gem update --system
Updating rubygems-update

C:\Users\Miller>gem --version

Installing Rails

The easiest way to install Rails is with RubyGems.

C:\Users\Miller>gem install rails
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...
Successfully installed rails-3.1.1
5 gems installed

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.


I’ve installed Rails, but I need to make sure everything works before I quit for the day.

C:\Users\Miller>rails new testapp
         run  bundle install
Fetching source index for http://rubygems.org/
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
=> 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!

  1. Anonymous says:

    Thanks so much! my professor didn’t even know how to fix it. I was missing my native ‘json’ gem and after following your instructions, that fixed me right up! Tank you!

  2. Steve says:

    Just to say thank you for creating this advisory on ruby on rails for Windows. Was a real life safer. Stephen

  3. Mohamed says:

    Thanks so much for this Tutorial

  4. Daniel says:

    Just when I was ready to rip my hair out, looking for a way to install rails on my windows system, I found this guide and I can say you really saved me from baldness sir!

  5. Ruby says:

    Really good!!! Thanks a lot

  6. rajesh says:

    Thanks a lot i am a new bee it really worked fantastic for me excellent. Thanks for sharing such a gr8 info

  7. Shaw says:

    Thank you!!

  8. Renuka says:


    ruby dk.rb init – cmd is indeed useful.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>