Ruby on Rails
RailsonWindowsCygwin (Version #33)

For those of you who prefer Windows as your development environment, yet are NIX-inclined, here is a way to install Ruby on Rails for development & testing use under Cygwin.

When you’re done, all your command prompt work can be done under Cygwin.

At the time of this writing, Cygwin includes Ruby 1.8.4 and MySQL is on verison 5.0.

For an alternative using SQLite3 see RailsOnWindowsCygwinWithSQLite3.

(Note: I just went through this and didn’t find all the issues covered in one place, so I put this together. Feel free to refactor, I’m a bit of a rails noob.)

1. Install Cygwin

Run Cygwin’s setup.exe as normal (for expanded install instructions, see below). From the package list, under Dev, make sure to choose:

  • Ruby
  • gcc
  • subversion (optional, but you’re going to be talking to a subversion server somewhere, right?)

You’ll be using gcc to build the Cygwin version of MySQL, even though you will not be running it (see below).

2. Install MySQL for Windows

Just download MySQL 5.0 Windows Installer. I used the full version as opposed to the Essentials version.

This will install MySQL as a Windows service, meaning it will be running full time. Follow the installation wizard for security settings, etc.

3. Install MySQL generic source package & build it

This is at the bottom of the page and is labeled Tarball.

Extract the tarball into a tmp directory and do the normal Linux things:

  • ./configure
  • make install

This will take a bit. You’re compiling MySQL 5.0 for use under Cygwin. You’re not going to run this version, but you need it around, especially the source, in order to build the Rails MySQL connector below.

4. Install Ruby Gems

Do this the normal way. Download Gems and do the normal extraction and then execute ruby setup.rb

5. Install Rails

Now that you have Gems, you can install Rails. Execute gem install rails --include-dependencies

If you are behind a proxy, use -p (for full documentation, see the GEMS Manual). This applies to step 6 below as well.

since Rails 2 is out, I find that adding —version 1.1.6 to this command is important

6. Install the MySQL Gem

Execute gem install mysql. When prompted for the choice, do NOT install the mswin32 version. Install the latest unix version.

That’s it. Ruby scripts, Rails commands, and connections to MySQL should now work.

Expanded Install Instructions

For those of you new to rails, cygwin is VERY helpful, since Winblows isn’t the greatest environment for development (also, I’m too poor to buy a Mac and my HD can’t hold a linux partition… woe is me.) Here is the straightforward way to do this:

  • Download Cygwin’s setup.exe
  • Create a new folder whereever you like, typically C:\cygwin
  • Move the setup.exe to this new folder.
  • Run it!
  • Select “Install from Internet”
  • Make sure your root directory points to the one you just created. Install for “All Users” with default text file type being “Unix / binary”.
  • Select a new folder to store the package files cygwin downloads. I use C:\Program Files\cygwin-files as my folder, but it don’t matta.
  • Pressing ‘Next’ twice should bring you to the mirror sites available for downloading packages from. I picked some .com’s or other sites I trusted more. Just select two or so, and click next. It will download package info, and will allow you to select which ones you want (see above for the required ones).
  • Once done, you’re done! Click on cygwin.exe, and have fun!
    If you want to know more about how to use Cygwin, see this: Cygwin How-to
  • If you are confused as to how you can mount your C drive in Cygwin, just restart! It should appear under /cygdrive/c automatically.

Common Errors

  • If you get a rake error “Uninitialized Constant Mysql”, then you likely have the MSWin32 Gem installed. Go remove it from the gems directory and try again.
  • If you’re getting Ruby errors, you’re likely either attempting to run Windows Ruby from a Cygwin prompt, or Cygwin Ruby from a Windows command prompt. Review your installation and try again.
  • If ruby complains that it Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (during rake db::migrate, for example), you need to force access to the MySQL server via IP. In your database.yml[database.yml], change all occurances of localhost to 127.0.0.1.
  • If after running ruby setup.rb and you get a complaint like:
    ruby: No such file to load -- ubygems (LoadError)
    then you need to run unset RUBYOPT Then run the gem installer again. That should fix it! (Thanks to PluitSolutions for the tip)
  • If upon creating your first rails app you get something like this:
    > rails dummy_app
    "No such file or directory" - /dev/urandom
    Then check out this ruby forum topic

For those of you who prefer Windows as your development environment, yet are NIX-inclined, here is a way to install Ruby on Rails for development & testing use under Cygwin.

When you’re done, all your command prompt work can be done under Cygwin.

At the time of this writing, Cygwin includes Ruby 1.8.4 and MySQL is on verison 5.0.

For an alternative using SQLite3 see RailsOnWindowsCygwinWithSQLite3.

(Note: I just went through this and didn’t find all the issues covered in one place, so I put this together. Feel free to refactor, I’m a bit of a rails noob.)

1. Install Cygwin

Run Cygwin’s setup.exe as normal (for expanded install instructions, see below). From the package list, under Dev, make sure to choose:

  • Ruby
  • gcc
  • subversion (optional, but you’re going to be talking to a subversion server somewhere, right?)

You’ll be using gcc to build the Cygwin version of MySQL, even though you will not be running it (see below).

2. Install MySQL for Windows

Just download MySQL 5.0 Windows Installer. I used the full version as opposed to the Essentials version.

This will install MySQL as a Windows service, meaning it will be running full time. Follow the installation wizard for security settings, etc.

3. Install MySQL generic source package & build it

This is at the bottom of the page and is labeled Tarball.

Extract the tarball into a tmp directory and do the normal Linux things:

  • ./configure
  • make install

This will take a bit. You’re compiling MySQL 5.0 for use under Cygwin. You’re not going to run this version, but you need it around, especially the source, in order to build the Rails MySQL connector below.

4. Install Ruby Gems

Do this the normal way. Download Gems and do the normal extraction and then execute ruby setup.rb

5. Install Rails

Now that you have Gems, you can install Rails. Execute gem install rails --include-dependencies

If you are behind a proxy, use -p (for full documentation, see the GEMS Manual). This applies to step 6 below as well.

since Rails 2 is out, I find that adding —version 1.1.6 to this command is important

6. Install the MySQL Gem

Execute gem install mysql. When prompted for the choice, do NOT install the mswin32 version. Install the latest unix version.

That’s it. Ruby scripts, Rails commands, and connections to MySQL should now work.

Expanded Install Instructions

For those of you new to rails, cygwin is VERY helpful, since Winblows isn’t the greatest environment for development (also, I’m too poor to buy a Mac and my HD can’t hold a linux partition… woe is me.) Here is the straightforward way to do this:

  • Download Cygwin’s setup.exe
  • Create a new folder whereever you like, typically C:\cygwin
  • Move the setup.exe to this new folder.
  • Run it!
  • Select “Install from Internet”
  • Make sure your root directory points to the one you just created. Install for “All Users” with default text file type being “Unix / binary”.
  • Select a new folder to store the package files cygwin downloads. I use C:\Program Files\cygwin-files as my folder, but it don’t matta.
  • Pressing ‘Next’ twice should bring you to the mirror sites available for downloading packages from. I picked some .com’s or other sites I trusted more. Just select two or so, and click next. It will download package info, and will allow you to select which ones you want (see above for the required ones).
  • Once done, you’re done! Click on cygwin.exe, and have fun!
    If you want to know more about how to use Cygwin, see this: Cygwin How-to
  • If you are confused as to how you can mount your C drive in Cygwin, just restart! It should appear under /cygdrive/c automatically.

Common Errors

  • If you get a rake error “Uninitialized Constant Mysql”, then you likely have the MSWin32 Gem installed. Go remove it from the gems directory and try again.
  • If you’re getting Ruby errors, you’re likely either attempting to run Windows Ruby from a Cygwin prompt, or Cygwin Ruby from a Windows command prompt. Review your installation and try again.
  • If ruby complains that it Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (during rake db::migrate, for example), you need to force access to the MySQL server via IP. In your database.yml[database.yml], change all occurances of localhost to 127.0.0.1.
  • If after running ruby setup.rb and you get a complaint like:
    ruby: No such file to load -- ubygems (LoadError)
    then you need to run unset RUBYOPT Then run the gem installer again. That should fix it! (Thanks to PluitSolutions for the tip)
  • If upon creating your first rails app you get something like this:
    > rails dummy_app
    "No such file or directory" - /dev/urandom
    Then check out this ruby forum topic