I recently started playing around with Ruby and Rails. I haven’t done much with it yet short of these CodeSchool courses, but it seems really powerful. I did run into a bit of a hiccup when installing it, though, so I thought I’d write a quick post on how to get it installed in windows.

Just a quick note: as of this writing the latest version of Ruby is 1.9.3

Step 1 – Get The Files

Ok, the first thing you need to do is get the files you’re going to install. A quick search for “Ruby on Rails download” will lead you to this page: http://rubyonrails.org/download. The page tells you to download Ruby and RubyGems, but you’ll also need one more file.

The list of files you need are:

  • Ruby: rubyinstaller-1.9.3-p194.exe
  • RubyGems: Click the “Zip” button at the top (1.8.24 as of this writing)
  • Ruby DevKit: DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

Note these files are the latest versions as of this writing. You may see newer ones if they have been updated.

OK, so you have the three installer files now, so let’s get started.

Step 2 – Install Ruby

This is pretty straight forward. Open the Ruby installer (rubyinstaller-1.9.3-p194.exe) and the first thing you need to do is review and accept the license agreement:

Ruby Installer Screen 1

Then click “Next >” and you’ll be given a choice on where to install it to. I don’t like to clutter up my C: drive, so I installed it to C:\langs\Ruby193. You can keep it as the default or put it wherever you want.

Ruby Installer Screen 2

You’ll probably want to check the three tick boxes as well.

  • Install Tcl/Tk support – This installs libraries for making GUI applications with Ruby
  • Add Ruby executables to your PATH – This will allow you to run “ruby” and other ruby exes from any directory in the command prompt.
  • Associate .rb and .rbw files with this ruby installation – The only reason you may not want this is if the files are already associated with something else.

Now, click install and it will copy all the files and then you’ll see the complete screen:

Ruby Install Complete Screen

Click “Finish” and you’re done installing Ruby!

Step 3 – Install RubyGems

RubyGems “is the standard Ruby package manager.” Once installed, you’ll use it to install Rails into your Ruby installation. Unzip the RubyGems file (rubygems-1.8.24.zip) to a temp directory. I chose C:\temp\. Now, navigate to this folder in Windows Explorer and you should see these files:

Ruby Gems - Extracted Files

You’ll note here that there’s a “setup.rb” file. That’s what we want to run. So fire up the command prompt (Windows Key + R » Type: cmd » Hit Enter) and move to that directory. Then, you’ll want to run the command “ruby setup.rb” and you should see something like this

Ruby Gems Install Text

Note: if you didn’t add Ruby executables to your PATH, you’ll have to provide the full path to Ruby. Also, If you did Associate .rb and .rbw files with the ruby install, you can just run “setup.rb”.

OK! So, Ruby and RubyGems are installed. Woohoo! Almost there.

Step 4 – Install Rails

Now, the instructions on RubyOnRails.org/Download tell you to run “gem install rails”. So do this in your command prompt window and hopefully you’ll see a bunch of messages saying “Fetching: xxxx (100%)”, “Successfully installed xxxx”, “Installing ri documentation for xxxx” and “Installing RDoc documentation for xxxx”. Make sure that you allow ruby to connect to the internet through your firewall if you have one (and you should). I’m not going to post a screenshot since there’s a lot of messages and it’s all pretty much summed up by the previous few lines. Note you may see a “file ‘lib’ not found” message. This hasn’t caused me any issues so it’s probably ok. :)

Step 5 – Install the DevKit

This step isn’t in the RubyOnRails.org/Download list. Their next step is to create a new rails site, but when I try that it gives me this error message:

So, I do what it says and run “gem install json -v ’1.7.3′” and get this message:

It all comes back to to the DevKit. Open up the DevKit executable (DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe). It’s a self extracting zip file and I chose to extract it to C:\langs\ruby193\devkit just to keep everything nicely together. ( I’m actually not entirely sure if you need the files after you install it so if you know, drop a comment. :) )

Once you have it extracted, get in your command prompt and change directory until you get into the folder where you extracted it (i.e. C:\langs\Rub193\DevKit) and run this command: ruby dk.rb init This initializes the DevKit installation. You should see a message like this:

The first line, beginning with [INFO] should show the path you installed Ruby to in Step 2. Don’t worry about looking at the config.yml file unless you know you have other Ruby installs you want (or don’t want) to link it to.

Next, you have to run this command: ruby dk.rb review This will spit out something along these lines:

This should match the path to whatever was detected when you ran ruby dk.rb init (which should be your Ruby install directory from Step 2).

Finally, once you’ve verified that these are correct, run this command: ruby dk.rb install
This should give you this message:

And your done! DevKit is installed!

Step 6 – Setup A Test Rails Site

All that’s left is to set up a test rails site and you’ll be ready to roll. I created mine here: C:\www\rails\TestRailsSite but you can create yours anywhere. Just get to the directory in the command prompt and run this command: rails new . (Don’t forget the period at the end to let it know you want to use the current directory.)

You’ll see it create a bunch of files and run a bunch of fun stuff. It will also install a few gems and eventually it should complete with no errors.

Step 7 – Test It!

To test it, just run rails server (or rails s) and point your browser to http://localhost:3000/

Conclusion

That’s it! You’re done. I hope this post has helped someone out who was having the same issues as me. If you have any questions or comments drop them in the form below.

Happy programming.