I just recently decided to start working with Ruby on Rails, as I’m interested in seeing why it has become all the rage these days. Before I could start learning Ruby on Rails, I, of course, first needed to setup a development environment on my Windows desktop to help get me started. Well, there’s a ton of documentation and help available online to aid us helpless Windows users, but I was unable to find a comprehensive walk through or discussion. It seems there really is no single definitive solution (there is no real IDE like Visual Studio in the Ruby world and there are myriad ways to do things). Through quite a bit of research, however, I was finally able to make a (somewhat) informed decision on what I wanted my environment to look like. This post will detail the setup that I chose, with instructions on getting it up and running on your own Windows desktop.
First, a couple of quick notes about the technologies:
e – Text Editor: Although I mentioned that there doesn’t seem to be agreement as to what the best way to setup a Ruby on Rails development environment (on the Windows platform) is, there is definitely consensus among the masses as to what the best editor for programming in Ruby is: TextMate. Unfortunately, however, TextMate is Mac only, so for those of us who use Windows, we’ll have to settle for something else. Well, after much reading and going back and forth, I decided to go with e – Text Editor. It is supposed to be the closest thing to TextMate that you can get on a PC; it even supports TextMate command and snippets. I have a little bit of experience with e, as I used it through many of its initial betas. But as soon as it came out of beta I had to either pay up or move on to something else. Well, at the time I chose to stick with good ‘ole Notepad++, as it’s open source and meets most of my needs. After reading all of e’s recent praises, however, I’ve decided to give it another try, and this time I’ll dig deep to see what kind of advantages it offers. At first glance it does seem incredibly powerful, and its integrated packages make it ideal for developing in a number of languages.
Cygwin: Most of you Windows users probably already have some experience with Cygwin, but for those who don’t, here’s a quick rundown. Cygwin is “a Linux-like environment for Windows” that allows Windows users to take advantage of the power of a lot of the Linux tools without actually running Linux.
PostgreSQL: I’ve used PostgreSQL in the past, and will be using it on a new project that I’m working on, so I thought I’d give it a spin. That said, there are many databases out there, so you should choose the one that best meets your needs. If you want to use a different database and need help on the installation, however, you’ll have to find it somewhere else, as I’ll be covering installation of and connection to PostgreSQL in this post.
Before I go on, a few disclaimers:
- I set this environment up on a Windows Vista Ultimate x64 box, and haven’t tested it on any other operating systems.
- I do have both the “standalone Windows” and Cygwin environments installed on my machine, but have read in *numerous places that this can cause problems. I haven’t had any issues as of yet, but am definitely living on the edge. You may not want to.
Note: Other than trying to figure out for yourself which environment best meets your needs, there is really no reason to install both the “standalone Windows” and Cygwin environments on your machine. So unless you like to experiment and play around with different configurations and tools, you’ll probably want to choose one or the other.
Setting Up a Standalone Windows Environment
I decided to setup a standalone Windows environment in addition to the Cygwin environment, as I read in a couple of places that Ruby on Rails on Cygwin doesn’t perform all that well. That said, I haven’t had any major performance issues with the Cygwin environment up to this point.
1. Install e – Text Editor – There is a 30 day free full-featured trial available. If you like it, though, you’ll have to pay $34.95 for a license.
2. Install Ruby via the Windows Installer.
3. Install RubyGems.
4. Install Rails:
- In the command prompt, type gem install rails –include-dependencies.
- If this doesn’t work, you’ve likely got RubyGems problems. You can download the stand-alone package for Rails and install from there, but you’ll likely want to take care of your RubyGems issues before moving on.
5. Create a Rails Application:
- In the command prompt, use cd to get to the directory where you want to create an application.
- In the command prompt, type rails ApplicationName and hit enter.
6. Install PostgreSQL:
- Download the latest win32 version of PostgreSQL (64-bit is not currently supported on Windows systems).
- Initiate the installer and walk through the wizard. A couple of potential “gotcha” spots:
- Let the installer create a new Windows account so PostgreSQL can run as a service (I accepted the default postgres account and specified my own password).
- Let the database initialize a cluster for you.
- Install postgres-pr gem, which is a Ruby driver for PostgreSQL:
- Command line: gem install postgres-pr.
- Using the pgAdminIII gui that is installed by default with PostgreSQL, create your application databases. Follow the Ruby on Rails naming convention of ApplicationName_development, ApplicationName_test, ApplicationName_production when naming them.
- Configure your application to connect to the database(s):
- Open up your config/database.yml file and enter the following information for, at the very least, the development database:
- adapter: postgresql
- database: your_database
- username: postgres
- password: YourPassword
- host: localhost (assuming that you’re running PostgreSQL locally)
- Open up your config/database.yml file and enter the following information for, at the very least, the development database:
- Test your database connectivity:
- From the top level of your Rails application, type the following at a command prompt: rake db:migrate.
- If you get a response similar to this: (in c:/dev/YourWebApplication), you are good to go. If you get an error message, walk through the steps again, double-checking your configuration and fixing any mistakes (a Google search of the error is probably the best place to start).
Setting Up a Cygwin Environment
1. Install e – Text Editor – There is a 30 day free full-featured trial available. If you like it, though, you’ll have to pay $34.95 for a license.
2. Install Cygwin:
- Download the Cygwin Setup.exe and double-click it to initiate the install.
- Step through the install wizard, accepting the defaults until you get to the “Select Packages” dialog.
- In the “Select Packages” dialog, make sure that Ruby and Subversion are installed.
3. Install Ruby Gems:
- Download the latest version.
- From a Cygwin prompt, type: ruby “pathtorubygemsdownloaddirectory\setup.rb”
4. Install Console – This isn’t required, but it’s pretty nifty. Note that I had issues with a couple of the Console versions on Vista Ultimate x64. I finally found a version that has worked well for me. It is 2.00.125. See credit for this discovery in the links at the end of this post.
5. Setup e – Text Editor to open from Cygwin:
- Setup a Windows Path variable to point to C:\Program Files (x86)\e
- Open up your Cygwin .bashrc (if per user, it’s located at C:\Cygwin\Home\UserName) and add “alias e=’cygstart e’” under the “Aliases” section.
Helpful Resources That Guided Me in the Right Direction:
- A Mac-esque Rails Development Environment on Windows – A very helpful blog entry that details setting up a Rails development environment on Cygwin. Through this entry, I discovered Console, the sweet command line utility that I mentioned in the “Setting Up a Cygwin Environment” section above, and how to setup e – Text Editor to open from within Cygwin.
- So far, it’s RoR blog – A general Ruby on Rails (on Windows) blog that contains some useful information.
{ 3 comments… read them below or add one }
I can recommend Aptana Studio as a Visual Studio-like all-in-one Rails IDE. Performance and convenience on Windows Vista Home Premium is OK – I dual-boot Ubuntu Fiesty Fawn on the same machine, and Rails performance “feels” quite a bit snappier, especially when running Mongrel or Webrick.
Hi,
You have written a good article and have done some good research.
Thanls
This line:
Command line: gem install postgres-pr.
Saved my day. Thx a lot for this article!