Rails development on Windows!



Yes, it can be done! Contrary to popular belief… Windows can be a great Rails development platform. I know that those Mac guys have you all convinced that it’s too hard and painful to do and you should just go be a switcher. Well today I am going to show you, with a little work, you can be up and running with ease….similar to a Mac.

To begin, I wanted to say that the basis for this article orginally came from a post over at Garbage Burrito on how to get a Mac-esque development environment using windows. After being asked a few times at my local Ruby group how I develop on a Windows machine… I have decided to go a little more in depth and show you exactly what I’ve come up with. So here we go!

Most of you may already know that Sqlite3 is the default database used by Rails now in 2.02. This can be easily changed using the ‘-d’ parameter when using your ‘rails’ command. The reason I mention this is because I’ve been using Sqlite3 for a bit and have had a bit of difficulty when it comes to using add_column in my migrations. For that reason I am going to suggest installing MySQL. If you know what you’re doing and don’t want MySQL, go ahead and skip this step.

Step 1 | With that being said… Go install MySQL. You can easily find it at their site. I suggest not grabbing the ‘Essentials’ version just to make sure that you have everything you need if the time comes. Make sure you go through the installer and at the end you’ll want to use the ‘Server Instance Config Wizard’ to setup the server.

Step 2 | Go install e-Text Editor! I have used a bunch of text editors to try and get that TextMate feel but this is so far the closest Windows alternative. If you like it, please buy it. The creator updates very frequently and I’m sure he would love your support.

Step 3 | Since e-Text Editor is a TextMate clone… it uses a lot of UNIX commands. So we’ll now need to now install Cygwin. This is a emulated UNIX shell that can run under Windows. This also helps since a lot of the tutorials for Rails were created under Mac/Linux… you can easily follow along. Pretty much click through the installer. There are only a couple places to make sure settings are correct. When you hit the ‘Choose Installation Directory’ screen, you will want to make sure that ‘Install For’ is set to ‘Just Me’ and the ‘Default Text File Type’ is set to ‘Unix / binary (RECOMMENDED)’. These are probably the default settings but I wanted to make sure that you get this correct. Go ahead and continue clicking through the installation screens until you get to the ‘Select Packages’ screen. Think of these as a list of ‘addons’ for Cygwin. You will need a bunch of them so I will list all that I use. To make it easier, click on the ‘View’ button until it changes to ‘Full’. Now we can see all packages available. These are the packages I have installed (many are selected by default but these are extras you will need):

Go ahead and finish going through the installer. It may install for a while, that is normal.

Step 4 | Do yourself a favor and install Console. This very useful program lets you have tabbed command prompt windows open. Once that is installed you will want to go into settings and add a tab for Cygwin. Name it whatever you want but you’ll want to enter this command ( c:\cygwin\bin\bash –login -i )into the shell field. Enough said.

Step 5 | Install Ruby Gems. Download and unzip to your system. I put mine in the root directory, doesn’t really matter where it goes. Once you have that done… use Cygwin to navigate the the Ruby Gems folder. Then install Ruby Gems by invoking setup.rb.

  1. cd c:
  2. cd /Ruby\ gems (or where ever you put it)
  3. ruby setup.rb

Step 6 | Install Rails. Now what you’ve all been waiting for… Ruby on Rails. Rails will come to you as a ‘Gem’. It’s really just a kind of package management, which is really great for keeping things up to date. You can install any gem using the ‘gem’ command and a sequence of parameters.

  • gem install rails --include-dependencies

When going through this process, the package management will ask you to install other gems as well. These are OK as Rails has dependencies and we want them included. These should be:

  • actionpack
  • activerecord
  • activeresource
  • activesupport
  • rake

Step 7 | Install other needed Gems. This may be different for all of you, but since we are using MySQL… we should install the gem that binds rails to it. I will also list some others that I have been using. Please let me know what you start out with in the comment section.

  • gem install mysql
  • gem install mongrel
  • gem install haml (purely preference)
  • gem install rspec
  • gem install rspec-haml-scaffold (purely preference)

Step 8 | Try it out! Hoping that I didn’t miss anything here… this should work! From now on you’ll be using Cygwin as your command line editor. When you start Cygwin, you should be placed in your ‘home’ directory. I usually make a directory called ‘websites’ or something similar. I recommend this so you don’t have your projects scattered all over your home directory.

  • mkdir websites

Now you will want to cd into your ‘websites’ directory so that we can make a new Rails project. Go ahead and make the obligatory test blog using this command.

  • rails blog -d mysql

Again, now that Sqlite3 is the default database for Rails… you’ll need to add the ‘-d’ parameter with what database you’d like to use. As previously discussed, we will be using MySQL.

If all works correctly, you should see Rails creating your directory structure and all is well! If not, go ahead and leave a comment on how much I suck at writing tutorials. :-)

Hope this helps the Rails/Windows community and again please let me know if there is anything I can add to this article.

Thanks to Ben Kittrell of Garage Burrito for laying the ground work with his original article.

Similar Posts:



9 Responses to “Rails development on Windows!”

  1. Jim Neath says:

    I’ve never really had much of a problem using Windows as a development enviroment. I use Vista at work and OS X at home.

    I never really got along with e editor, so I use Intype (http://www.intype.info). Although the Intype project is far from being finished, it’s my full time editor on windows.

    Give the latest unstable release a whirl: http://intype.info/forums/discussion/484/how-to-get-unstable-releases/#Item_0

    The main reason I moved over to a mac was because I couldn’t find any background process plugins that worked on rails.

    I still think you can develop without many problems on windows, though.

  2. Soleone says:

    Thanks, good stuff!

    One minor typo:
    gem install rails –include-dependencies (with 2 dashes)

  3. Matt Polito says:

    @ Jim Neath

    I haven’t really had trouble developing in Windows either… that’s why I wanted to write this article to help the community understand that it’s not a ‘Mac’ thing.

    Also, I’ve tried Intype in the past and liked it, because it was very alpha… I stopped using it. I heard that it’s been redesigned several times since the last time I used it.

    E is getting updated VERY frequently so you might want to give it a go again. Especially with Dr Nic’s new Ruby on Rails bundle.

  4. Matt Polito says:

    @ Soleone

    Thanks… I’ll make that change

  5. Just as a note…if anyone wants to use sqlite3 instead of mysql make sure you install the libsqlite3 cygwin package and the sqlite3-ruby gem:

    gem install sqlite3-ruby

  6. Matt Polito says:

    @Seth
    I personally have been using sqlite3 but have been having trouble with it as of late. That’s why I didn’t include it in this tutorial. I would assume that I’m the only one having this trouble but to avoid it in the article I just left it out for now. But it is the easier way to go.

    Maybe the readers can help! Everytime I use add_column and do a rake:db:migrate… I get a SQL error. The error seems to pertain to the VACUUM. Anyone know what’s going on?

  7. jtorres says:

    gem install sqlite3-ruby
    Just works.

    gem install mysql-ruby:
    ERROR: could not find mysql-ruby locally or in a repository

  8. Matt Polito says:

    @jtorres
    Thanks for the heads up. Seems that it’s just called mysql now.

    gem install mysql

  9. Matt Polito says:

    If anyone is getting an error of when trying to create a new Rails project… check out this link for some help: http://tinyurl.com/646789. Thanks to Carl Jackson for finding this

Leave a Reply