Skip to content

Instantly share code, notes, and snippets.

@agilous
Created March 2, 2012 00:05
Show Gist options
  • Save agilous/1954160 to your computer and use it in GitHub Desktop.
Save agilous/1954160 to your computer and use it in GitHub Desktop.
Ruby on Rails on Windows guide created 2009-03-13

I was recently forced to press my old Windows desktop system into an emergency Rails development platform. 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.

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.

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 at a command prompt.

Update RubyGems

  1. Run gem update --system on the command line.

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. a. 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. b. 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. c. 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.

  1. Install the SQLite gem by running gem install sqlite3-ruby on the command line. Select the mswin32 gem when prompted.

Install Rails

  1. Install the Rails gem by running gem install rails on the command line.
  2. To verify the install run rails -v on the command line.

Test Everything

  1. Change into a directory of your choosing and create a Rails project by running rails test-project on the command line.

  2. Change into the newly created project directory and verify that the server starts and the project is live.

  3. Create the databases by running rake db:create:all Notice! The syntatic shortcut of passing the field name and type to the migration generation script appears to have failed for some reason unknown to me at present. As a result, I will have to edit in the migration by hand before running the rake task to migrate the SQLite database.

  4. Create the users table via the SQLite command line as follows:

    C:\dev\test-project>sqlite3 development SQLite version 3.6.11 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> CREATE TABLE users(username varchar(10)); sqlite> .quit

    C:\dev\test-project>

  5. Create a migration by running the following on the command line:

    C:\dev\test-project>ruby script\generate migration add_password_to_users_table exists db/migrate create db/migrate/20090314041958_add_password_to_users_table.rb

    C:\dev\test-project>

  6. Edit the migration file located in the db\migrate directory as follows:

    class AddPasswordToUsersTable < ActiveRecord::Migration def self.up add_column "users", "password", "string" end

    def self.down remove_column "users", "password" end end

  7. Run rake db:migrate on the command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment