Trying to remain agile in a BIG design world.

During a recent Cincinnati Ruby Brigade meeting a new member who was running Windows would have benefited from a minimalist guide to installing Ruby on Rails on Windows. A few days later I was forced to press my old Windows desktop system into service as an emergency Rails development platform. So I decided to write this post.

Thanks to All About Ruby for providing a starting point for my research for this post.

Nota Bene: These instructions are Windows XP specific. If you’re using another flavor of Windows YMMV. Also, all references to software version numbers are current only at the date of this posting.

Install Ruby

  1. Download the One-Click Ruby Installer for Windows.
  2. Run the installer. I unchecked the option to install the SciTE text editor which saved a whopping 1.5MB of storage.
  3. If you so desire, you can verify that the install succeeded by running ruby -v on the command line:
  4. C:\>ruby -v
    ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
    
  5. Update RubyGems by running gem update –system on the command line:
  6. C:\>gem update --system
    Updating RubyGems...
    Attempting remote update of rubygems-update
    Successfully update rubygems-update-1.3.1
    Updating version of RubyGems to 1.3.1
    Installing RubyGems 1.3.1
    [...]
    RubyGems system software updated
    
  7. Again, verify the install succeeded by running gem -v on the command line:
  8. C:\>gem -v
    1.3.1
    

Install SQLite

  1. From the Precompiled Binaries For Windows section download the command-line program (sqlite_X_Y_Z.zip) and the SQLite library DLL without the TCL bindings (sqlitedll_X_Y_Z.zip) unless you need the TCL bindings.
  2. Copy the contents of both ZIP files into a directory of your choosing. I chose C:\sqlite. Others have chosen to place them in the bin directory under the base directory chosen during the Ruby installation, typically C:\ruby\bin. I chose a separate directory so that future upgrades of Ruby do not break my SQLite installation.
  3. If you chose a separate directory in the previous step, like C:\sqlite, you will want to add that directory to your PATH environment variable.
    1. To do so, navigate Windows Explorer until you can see My Computer. Right click the My Computer icon and select Properties. Select the Advanced tab and then the
      Environment Variables button.
    2. If you have sufficient privilege, I recommend adding the path to the PATH variable under the System variable section so that SQLite is available to all system users. However, if you do not have sufficient privilege OR are certain that the current user is the only user that will require access to SQLite then you are free to add the path to the PATH variable under the User variables section.
    3. To add the path, select the PATH variable and click the Edit button. Add the appropriate path, in my case C:\sqlite, to either the beginning or end of the existing PATH string then click the OK button.

    WARNING! Be careful that you do not corrupt or delete the existing PATH string.

  4. Install the SQLite gem by running gem install sqlite3-ruby on the command line. Select the mswin32 gem when prompted.
  5. C:\>gem install sqlite3-ruby
    Select which gem to install for your platform (i386-mswin32)
     1. sqlite3-ruby 1.2.4 (ruby)
     2. sqlite3-ruby 1.2.3 (x86-mingw32)
     3. sqlite3-ruby 1.2.3 (mswin32)
     4. sqlite3-ruby 1.2.3 (ruby)
     5. Skip this gem
     6. Cancel installation
    > 3
    Successfully installed sqlite3-ruby-1.2.3-mswin32
    Installing ri documentation for sqlite3-ruby-1.2.3-mswin32...
    Installing RDoc documentation for sqlite3-ruby-1.2.3-mswin32...
    

Install Rails

  1. Install the Rails gem by running gem install rails on the command line:
  2. C:\>gem install rails
    Successfully installed rails-2.2.2
    1 gem installed
    
  3. To verify the install run rails -v on the command line:
  4. C:\>rails -v
    Rails 2.2.2
    

Test Everything

Let’s mimic the first couple of minutes of the famous Creating a weblog in 15 minutes video to test things out.

  1. Change into a directory of your choosing and create a Rails project by running rails blog on the command line:
  2. C:\dev>rails blog
    	create
    	create app/controllers
    	create app/helpers
    	create app/models
    	create app/views/layouts
    [...]
    
  3. Change into the newly created project directory, verify that the server starts, and that the app appears at http://localhost:3000:
  4. C:\dev\blog>ruby script\server
    -> Booting WEBrick...
    -> Rails 2.2.2 application started on http://localhost:3000
    -> Ctrl-C to shutdown server; call with --help for options
    [2009-03-14 13:55:45] INFO  WEBrick 1.3.1
    [2009-03-14 13:55:45] INFO  ruby 1.8.6 (2007-03-13) [i386-mswin32]
    [2009-03-14 13:55:45] INFO  WEBrick::HTTPServer#start pid-192 port-3000
    
  5. Run the scaffold generator script:
  6. C:\dev\blog>ruby script\generate scaffold Post title:string body:text
    	exists app/models
    	exists app/controllers
    	exists app/helpers
    	create app/views/posts
    [...]
     dependency model
    	exists	app/models/
    	exists	test/unit/
    	exists	test/fixtures/
    	create	app/models/post.rb
    	create	test/unit/post_test.rb
    	create	test/fixtures/posts.yml
    	create	db/migrate
    	create	db/migrate/20090315055640_create_posts.rb
    
  7. Run rake db:migrate on the command line:
  8. C:\dev\blog>rake db:migrate
    (in C:\dev\blog)
    ==  CreatePosts: migrating ======================================================
    -- create_table(:posts)
       -> 0.0940s
    ==  CreatePosts: migrated (0.0940s) =============================================
    
  9. Start the server again and visit http://localhost:3000/posts, click the New post link, and create a new post.

There you have it. Go ahead and finish the rest of the Creating a weblog in 15 minutes video and leave me a comment if you encounter any trouble.

Coming Soon! Git on Windows.

§17 · March 15, 2009 · Rails, Ruby · · [Print]

  • http://www.artificialweb.net/ Stalyn8

    Thank you!

  • Nik

    Do we need a web server like Apache to test the application? It is not mentioned here but when I try to run the server I have an error message.
    Thank for the help.

  • https://www.budgetsketch.com/ Bill

    Rails installs the WEBrick (http://www.webrick.org/) HTTP server. Think of it as Apache Light implemented in Ruby. If you reply with the error you're receiving we'll see if we can help. Just copy and paste the command line output in your reply.

    Good luck!

  • https://www.budgetsketch.com/ Bill

    Rails installs the WEBrick (http://www.webrick.org/) HTTP server. Think of it as Apache Light implemented in Ruby. If you reply with the error you're receiving we'll see if we can help. Just copy and paste the command line output in your reply.

    Good luck!