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
- Download the One-Click Ruby Installer for Windows.
- Run the installer. I unchecked the option to install the SciTE text editor which saved a whopping 1.5MB of storage.
- If you so desire, you can verify that the install succeeded by running ruby -v on the command line:
- Update RubyGems by running gem update –system on the command line:
- Again, verify the install succeeded by running gem -v on the command line:
C:\>ruby -v ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
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
C:\>gem -v 1.3.1
Install SQLite
- 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.
- 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.
- 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.
- 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. - 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.
- 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.
- 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
- Install the SQLite gem by running gem install sqlite3-ruby on the command line. Select the mswin32 gem when prompted.
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
- Install the Rails gem by running gem install rails on the command line:
- To verify the install run rails -v on the command line:
C:\>gem install rails Successfully installed rails-2.2.2 1 gem installed
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.
- Change into a directory of your choosing and create a Rails project by running rails blog on the command line:
- Change into the newly created project directory, verify that the server starts, and that the app appears at http://localhost:3000:
- Run the scaffold generator script:
- Run rake db:migrate on the command line:
- Start the server again and visit http://localhost:3000/posts, click the New post link, and create a new post.
C:\dev>rails blog create create app/controllers create app/helpers create app/models create app/views/layouts [...]
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
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
C:\dev\blog>rake db:migrate (in C:\dev\blog) == CreatePosts: migrating ====================================================== -- create_table(:posts) -> 0.0940s == CreatePosts: migrated (0.0940s) =============================================
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.