Running Rails 3 on Windows

Well, the long-awaited release of Ruby on Rails 3 is now out and all of the Mac and Linux junkies are busy gem-installing the latest version of the framework.  What about all the lonely Windows developers out there looking through their windows (pun intended) and wondering what it’s like on the other side of the fence?

Good news!  It is actually pretty easy to setup and run Rails 3 on your Windows system.  I mainly run on Macs these days but have a couple Windows systems still kicking around and thought I would give a go.  It is actually pretty straight-forward now and works really well.  Follow the steps:

Install Ruby

Rails 3 requires at least Ruby 1.8.7 and is happy using Ruby 1.9.2, I opted for the latest and greatest.

  1. Head over to RubyForge for the Ruby Installer by Luis LavenaDownload 1.9.2-p0 for the latest.   A nice feature of this Ruby installer is the latest gem executable is built in, which is version 1.3.7 at the time of this writing and you won’t have to install it yourself.
  2. I installed in C:\Ruby192, which is the default, and added C:\Ruby192\bin to my path so Windows can find the Ruby executables.

Running the Ruby version command from a new command prompt:

ruby -v

ruby-version

If you get a file-not-found or some other undesirable result then the path setting isn’t likely correct or you may want to try closing the command prompt and opening a new one.

Install Ruby on Rails

This is a tough one:

gem install rails

UPDATE: A reader points out of issues with installing Rails as pointed out by a post on the Ruby Forum. The issue was solved by simply adding a –pre to the gem command to install Rails.

gem install rails --pre

Everything you need to run Rails 3 gets installed with the exception of the SQLite3 Ruby gem which Rails uses as the default database provider:

Rails3gems

gem install sqlite3-ruby

You should see a message similar to this:

sqlite3-ruby-gem

I use SQLite3 for most of my local development unless I need a database like MySQL or PostgreSQL.  Installing is trivial.

Installing SQLite3

If you look at the above message when installing the sqlite3-ruby you should notice the gem relies on the sqlite3.dll and it is recommended to use version 3.6.23.1, which you can download form here.  I grabbed 3.7.2 and it seems to work fine, your mileage may vary.  If you’re interested, get the latest from the SQLite3 downloads page.

Now with the sqlite3.dll in hand (unzipped from the download), copy to the bin directory of the above Ruby installation.  In my case that’s C:\Ruby192\bin, and that’s it.

Creating a Test Application

Now it’s time to test the new Ruby and Rails installation.  Pick a location to create the new application and run the new Rails command from a command prompt:

rails new testapp

This command creates a new directory called testapp and spits out a bunch of text along the way, looking something like this:

railsapp

Once done, change directory into the new testapp directory and run:

rake db:migrate

This will test your SQLite3 installation and create a new development database in the testapp\db directory called development.sqlite3.  If you get any errors it is likely the sqlite3.dll is not in your Ruby bin directory, check and come back.

Now from the testapp directory, fire up the Rails development server from a command prompt:

rails server

WebBrick fires up and looks like this:

rails_server

If there are errors reported than something has gone wrong.  If you see this screen, fire up your browser and browser to the address http://localhost:3000.  If all goes well, you will see this screen:

testapp_home

Click on the link below the title that reads “About your application’s environment”.  This gives a lot of detail about your Rails application configuration.

testapp_config

Congratulations!  You have the latest and greatest Ruby and Ruby on Rails running on the Windows platform.

Now go out and read Mike Hartl’s Ruby on Rails Tutorial for Rail 3 and create some applications.

  • Fred

    Thank you! Very useful! I was a” little lost” about how to resolve the need of sqlite3.dll.

  • Saddumal Bhasodia

    Nice. The only problem is that there are numerous gems that don’t install on windows thanks to the absense of a POSIX-like build environment. So if you don’t wanna trip, you would be better off using cygwin.

  • http://accidentaltechnologist.com Rob Bazinet

    @saddumal, yes, you are right. Many gems aren’t compatible but things are improving. I doubt Windows will be the platform of choice for Rails developers but some devs don’t have a choice. It does give a place for people to experiment though.

  • Anonymous

    Yes, there are certain gems that will not compile out of the box, but the major number of this, with 3rd party headers and libs will compile perfectly with RubyInstaller and the Development Kit, which is GCC based, reducing the issues of portability.

  • http://www.folkartplayhouses.com/ Scott

    Thanks, I really appreciate your help.

  • sharon

    Thanks for putting this up especially the bit on sqlite. However, I do want to point out that my installation of the rails did not go smoothly. I was getting similar error messages as the poster in the ruby forum (see http://www.ruby-forum.com/topic/211336). The suggested solution at the ruby forum worked for me. I had to use “gem install rails –pre” before rails would install successfully.

  • http://www.accidentaltechnologist.com Anonymous

    @sharon – thank you for pointing this out, I have updated the post to include the information. It’s interesting the –pre would be needed because Rails 3 is no longer prerelease, –pre is normally only used to install betas and release candidate versions of software.

  • mybirthstone

    That was breeze installation! Many thanks! Unfortunately, my codes from version 1.8.6 didn’t catch up. I’ll have to figure out how to make them compatible with this version.

  • Daniel

    /bows in gratitude

  • Pingback: Moving Instant Rails Forward | Accidental Technologist

  • http://accidentaltechnologist.com Rob Bazinet

    @Daniel – glad I could help.

  • Reuven

    I got this error on Windows 7:
    C:UsersReuven>gem install rails –pre
    ERROR: While executing gem … (Errno::ENOENT)
    No such file or directory – P:/

    So I created a drive P: by mapping it to \my IP addressc$ and that fixed it.

  • Pingback: Coders' survival guide to Startup Weekend | codefixes.com

  • http://twitter.com/Inficone Shivam

    Thanks for this excellent post. I was on lookout for Instant Rails package for installing rails 3 on windows when google landed me to your blog. Took me five minutes to get the whole thing running on Vista – keep up the good work.

  • Pingback: 6 Great Ruby on Rails 3 Learning Resources | Accidental Technologist

  • Kae

    I have ruby installed, but still can’t install rails with gem. All I get is:

    C:>ruby -v
    ruby 1.9.2p0 (2010-08-18) [i386-mingw32]

    C:>gem install rails –pre
    ERROR: http://rubygems.org/ does not appear to be a repository
    ERROR: Could not find a valid gem ‘rails’ (>= 0) in any repository

    C:>gem install rails
    ERROR: http://rubygems.org/ does not appear to be a repository
    ERROR: Could not find a valid gem ‘rails’ (>= 0) in any repository

    C:>

  • http://www.accidentaltechnologist.com Anonymous
  • Oj

    Hi I cant say thank you enough THANK YOU . . I am a new comer to rubies gems and rails and I was in the hole marked” installed instant rails on win7 but all the jucy rails tutorials are 1.9.2 & rails 3 managed to climb into another deeper hole ( I am ann alien in Linux land having lived in Bills back yard for many years ) marked “installed a cure it all VM with ubuntu rails stack only to find its a headless monster and I cant see the rails app in a browser ..and so on . so I googled “is there a new recent version of instant rails ” Now I m out of the whole and back on the rails chuckling away to myself thanks for your clear instructions that are in windows the language that I recognise .Thanks again thanks very much ,, I off down the track to ” M.Hart’s ” sidings to load up with tutoring .

  • Louiek88

    Followed to a T, and works like a charm! Great instructions. Thank you!

  • Deandwyer

    Hey RB,

    I have searched online for about 90 minutes and what you have written here is by the best I have seen. SO here is my question (please keep in mind I am literally brand spanking new at Ruby). I am uploading on windows using cygwin…I am getting this issue and haven’t seen anyone who can explain it…

    When I type gem install rails or gem install rails –pre I get the following message…

    *gem install rails
    *Successfully installled rails-3.0.0.rc2
    *I gem installed
    *Installing ri documentation for rails-3.0.0.rc2
    *File not found: lib

    Any suggestions that would help me overcome this little problem. Appreciate any help you might be able to provide my friend :-)

    Dean

  • http://www.accidentaltechnologist.com Anonymous

    @Dean – I believe the issue here is using cygwin to manage gems. I tried the same thing you were doing and got very similar results. I even went ahead, install Rails w/o using cygwin but then tried to install other gems under cygwin and they also failed.

    I think it has to do with paths setup under cygwin, which I did not try to debug. Maybe a post over at the cygwin forums may find an answer.

  • Andrew Okoye

    Excellent step-by-step instruction. Worked like a charm. Well done!

  • http://twitter.com/alextfish Alex Churchill

    A simple mkdir command fixes this, as described on this page: http://www.spritle.com/blogs/?p=915

  • Derron

    Thanx for the great walk through, got me started with Rails in less than 10 minutes :D

  • Jeans

    Like others said, your walkthrough is the best.

  • Pingback: 在windows上安装ruby on rails 3 | 肖阳昇的博客

  • dan

    Wow, This is the most pain free way I’ve every installed rails on windows …. ever. I was expecting faults and other issues and nothing happened. wow

  • Danlefebvre

    good stuff! thanks a lot for this great tutorial!

  • Anonymous

    SUPER EASY! I always ran into dumb issues while trying to install rails on linux but this…makes it soo easy and I don’t have to boot into the other OS.

    Great post! You saved me a lot of time.

  • changu

    Finally something that worked for me.
    Thanks very much!

  • Guest

    If you’re behind a proxy:

    change this:
    gem install rails

    to this:
    gem install –http-proxy http://proxy.yourproxy.com:8080 rails

    (replace the proxy url:port with your own info)

  • Pingback: “Ruby on Rails 3″ Railsをインストールできないとき | ゆる~くWebのこと

  • Anonymous

    Worked like a charm… finally I am on Rails 3.0… Thanks.

  • Virajdasondi

    great help….

  • Pingback: Super easy way to get started with rails 3 on windows. I tried it, it took about 3 commands and less than 5 minutes. INSANE! | Cesar Quinteros