Log In

Matt Briggs

"Not all code needs to be a factory, some of it can just be origami." - _why, the lucky stiff

Setting Up a Rails Development Environment on Windows

windows
by Matt Briggs on 11/17/09

Awhile back, DHH unleashed one of his many shitstorms with this comment

I would have a hard time imagining hiring a programmer who was still on Windows for 37signals. If you don't care enough about your tools to get the best, your burden of proof just got a lot heavier.

Now, he had reasons for this. Apart from that OSX is a great platform for web development pretty much out of the box, and that it both has the unix userland and the gcc toolchain, there are other reasons as well. Both the ruby and rails core teams are all on macs. Most rails developers are on macs. Ruby on windows is even slow compared to ruby on other platforms. Because of all of this, many rails plugins and ruby libraries are rarely (if ever) tested on windows.

Now, for some of us it isn't about caring, more about the price tag attached to apple products compared to the competition, and the whole value for money thing. I am getting pretty serious about rails, and will probably be picking up an iMac fairly soon, but it has taken me awhile to get to this point. For people who are not in the position of working with rails professionally, there is a high barrier to entry unless you are already a mac user.

Hopefully, this will help people get to where they can easily and effectively develop rails stuff on windows.

Environment

Now, a lot of people will suggest Instant Rails for getting going on windows. Personally, I would rather choose my own tools (I don't like doing dev stuff on MySQL), and while it is quick to get off the ground, you are pretty much stuck with that stack. Also, upgrading or changing individual bits are pretty tough.

Ruby

Most people will type "Ruby" into google, head over to ruby-lang.org, and click download.

DO NOT DO THIS

The "One-click Installer" is built using an obsolete visual c++ compiler, and will leave you unable to build native gems. The far superior alternative is to head over to http://rubyinstaller.org/ and hit download. Scroll down to the Ruby Installer builds, and find the latest 1.8.x executable (currently, this is rubyinstaller-1.8.6-p383-rc1.exe) Download that and install.

This will give you ruby, but the next problem we have is there is no gcc toolchain. To fix that, go back to http://rubyinstaller.org/, and click "Addons". Download "Dev Kit", and then extract it into your ruby directory. This is an archive that has gcc and friends, and a few stubs so that gems can build for you without any hassle.

Finally, make sure ruby is in your path. To do this, right click "My Computer", and (if you are on Vista/7) click on "Advanced System Settings". This will pop up another tabbed dialog, click on "Advanced", and then way at the bottom of the pane, click on "Environment Variables". In the bottom pane (marked System Variables), scroll down until you find Path. Hilight it and click "Edit". This will pop up a third dialog. In the bottom textbox, add "C:\Ruby\bin;" to the beginning of the line. Now click "apply" and "ok" until you have everything closed.

Think this is an insane process to add a value to an environment variable? So do I. What is one line in a console for any unix system is about 50 clicks or so in Windows. But hey, its cheap, and you get what you pay for.

To make sure this worked, open up a console and type ruby -v you should see something like this if everything is cool

D:\Users\matthew.briggs>ruby -v
ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]

Git

Currently, the two best source versioning systems out there are Git and [Mercurial][mercurial], everything else is at least a generation behind the times. The ruby world is pretty much universally behind git, and chances are you will need it as soon as you get passed "Hello, World" type stuff.

Head over to the msys-git project on google code, and download the latest version. At one point in the installer, it will ask if you want the msys stuff in your path, and warn you to say "no" unless you know what the consequences are. What they are talking about is that there are some commands (like find) that are named the same both on unix and on windows. If you say yes here, find will be using the unix version in your consoles. Personally, I have no problem with this, and will always say yes (it actually saves me having to install this stuff from other places). The choice is yours. The other thing it asks is if you want to use ssh or PuTTY, choose ssh.

Generate a key

This is used by a great many things, so you may as well do it now. Open up a console (or special git console if you chose to keep it out of your path), and type ssh-keygen. It will ask a bunch of questions, feel free to choose the default answer to them all.

This will generate an rsa key in your home directory, under .ssh/id_rsa and .ssh/id_rsa.pub. You probably want to keep a copy of these around, since they will be your identification when using any of a number of services. Also, keep in mind that your public key is used to authenticate you, so it is fine to give that to sites and services. Your private key is secret, anyone who has it can masquerade as you.

Getting some gems

In ruby, libraries are almost always packaged as "gems", and there is a package manager for these gems called "rubygems". First things first, lets grab rails. Open up a console, and type gem install rails. Rails has a boatload of dependencies, install all of them when prompted. Once everything is done, try typing rails -v at the console. You should see something like this

D:\Users\matthew.briggs>rails -v
Rails 2.3.4

Now that we have rails, lets get some other goodies. Type gem install mongrel ruby-debug sqlite3-ruby This will install the ruby debugger, mongrel (a much better pure ruby server for developing on, default is webrick which kind of sucks), and sqlite ruby bindings. There is one more step, sqlite requires a binary component you will have to grab seperately. Head over to the sqlite website, click download, scroll down to "Precompiled Binaries For Windows", and download the standalone dll. Extract the archive into your ruby/bin folder, and you should be done.

sqlite is an in memory database that is used by default in rails. what is great about it is that you don't even have to think about installing, configuring, or adminstrating a database server until you are ready to deploy to a production environment. If you think the whole dll thing is a pain, try a MySql install. I'm sure you will be back :)

Test to make sure it all works together

At this point, lets make sure everything is working. Try entering the following commands, you should see the same sort of following output

D:\Users\matthew.briggs>rails installtest
      create
      create  app/controllers
      create  app/helpers
      create  app/models
      create  app/views/layouts
      create  config/environments
      create  config/initializers
      create  config/locales
      create  db
      create  doc
      create  lib
      create  lib/tasks
      create  log
      create  public/images
      create  public/javascripts
      create  public/stylesheets
      create  script/performance
      create  test/fixtures
      create  test/functional
      create  test/integration
      create  test/performance
      create  test/unit
      create  vendor
      create  vendor/plugins
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  Rakefile
      create  README
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  config/database.yml
      create  config/routes.rb
      create  config/locales/en.yml
      create  db/seeds.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/new_rails_defaults.rb
      create  config/initializers/session_store.rb
      create  config/environment.rb
      create  config/boot.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  script/about
      create  script/console
      create  script/dbconsole
      create  script/destroy
      create  script/generate
      create  script/runner
      create  script/server
      create  script/plugin
      create  script/performance/benchmarker
      create  script/performance/profiler
      create  test/test_helper.rb
      create  test/performance/browsing_test.rb
      create  public/404.html
      create  public/422.html
      create  public/500.html
      create  public/index.html
      create  public/favicon.ico
      create  public/robots.txt
      create  public/images/rails.png
      create  public/javascripts/prototype.js
      create  public/javascripts/effects.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  doc/README_FOR_APP
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log

D:\Users\matthew.briggs>cd installtest

D:\Users\matthew.briggs\installtest>rake db:create
(in D:/Users/matthew.briggs/installtest)

D:\Users\matthew.briggs\installtest>rake test
(in D:/Users/matthew.briggs/installtest)
D:/Users/matthew.briggs/installtest/db/schema.rb doesnt exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a d
atabase, you should instead alter D:/Users/matthew.briggs/installtest/config/environment.rb to prevent active_record from loading: config.frameworks -
= [ :active_record ]

D:\Users\matthew.briggs\installtest>rake db:migrate
(in D:/Users/matthew.briggs/installtest)

D:\Users\matthew.briggs\installtest>ruby script/server
=> Booting Mongrel
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

At this point, open a browser, and go to http://localhost:3000. You should see the "Rails is installed

What Now?

Here is where things start to suck. We need some decent tools, and unfortunately they are pretty sparse in windows. This is a topic for another post, at which point I will go into some suggestions on editors, IDEs, debugging, and utilities for working on rails in windows.

my code blog.

what I am reading

Sidebar_clean_code

the people I follow

  • 24 ways
  • ABtests.com - Learn. Share. Improve your conversions today.
  • Ajaxian » Front Page
  • Alex Young
  • BEST IN CLASS
  • briancarper.net (λ)
  • Carbonica Blog Feed
  • Catalog Living
  • Clients From Hell
  • Clojure/core Blog
  • code is code
  • Coding Horror
  • CSS-Tricks
  • Daily Vim: Text Editor Tips, Tricks, Tutorials, and HOWTOs
  • David Chelimsky
  • dean.edwards.name/weblog
  • DHTML Kitchen News
  • disclojure: all things clojure
  • Edge Rails.info
  • End of Line
  • English - AkitaOnRails.com
  • Err the Blog
  • Evil Monkey Labs
  • Extra Cheese
  • Extra Cheese
  • For A Beautiful Web
  • Francis Hwang's site
  • Free Ruby and Rails Screencasts
  • Giles Bowkett
  • Hacker News
  • has_many :bugs, :through => :rails
  • Higgins for President
  • HTML5 Doctor
  • Information Is Beautiful
  • It's an all-you-can-leet buffet !
  • Jay Fields' Thoughts
  • JGUIMONT>COM
  • John Barnette
  • John Resig
  • K. Scott Allen
  • Katz Got Your Tongue?
  • Kirby's Dreamland
  • Kotaku
  • Kotka
  • Lambda the Ultimate - Programming Languages Weblog
  • Lazycoder
  • Loud Thinking by David Heinemeier Hansson
  • LukeW | Writings on Digital Product Strategy and Design
  • mir.aculo.us
  • MongoTips by John Nunemaker
  • Moonbase
  • No Strings Attached
  • Nuby on Rails
  • Official jQuery Blog
  • ones zeros majors and minors
  • opensoul.org by Brandon Keepers
  • Painfully Obvious
  • Painfully Obvious
  • Particletree
  • Paul Irish
  • Perfection kills
  • Plataforma Tecnologia Blog » English
  • Rails on PostgreSQL :
  • Railscasts
  • RedFlagDeals.com - Latest Deals
  • Relaselog | RLSLOG.net
  • remy sharp's b:log
  • Riding Rails - home
  • RightJS News
  • rmurphey
  • Room 101
  • Rubinius Blog
  • Ruby Best Practices
  • Ruby Inside
  • Ruby Quicktips
  • Ruby treats women as objects
  • RubyFlow
  • Signal vs. Noise
  • Slash7 with Amy Hoy - Home
  • Smashing Magazine Feed
  • Snail in a Turtleneck
  • Software Craftsmanship – Katas
  • St. on IT
  • Stevey's Blog Rants
  • Technomancy
  • Tender Lovemaking
  • Test Obsessed
  • Zed Shaw
  • The CSS Ninja
  • The GitHub Blog
  • The MongoDB NoSQL Database Blog
  • The Napkin ~ A Blog By Highgroove Studios
  • The UX Booth
  • The Word of Notch
  • the { buckblogs :here } - Home
  • Thoughts From Eric
  • Uncle Bob's Blog
  • VIM Tips Blog
  • Virtuous Code
  • Web Designer Wall - Design Trends and Tutorials
  • Wow! eBook - Great ebook, great site!
  • #<Mongoid::Criteria:0xb2d2098>
profile for Matt Briggs at Stack Overflow
Feed
atom 1.0

mattcode.net stack

Rightjs
Rails
Mongo
Dropbox