First step, download and install Cygwin. The latest version of Cygwin already includes Ruby 1.8.3, so you don’t need to download and build it.
I had One-Click Ruby installed in a separate directory, all set up and loaded with Gems (*cough*rails*cough*). Apparently it’s that double install that causes Cygwin Ruby to spit out the following error:
Ruby: No such file to load -- ubygems (LoadError).
A little digging revealed that the environment variable RUBYOPT was set to rubygems, causing Ruby to try and load the rubygems package. But while Windows Ruby places its libraries in c:ruby/lib/ruby/, Cygwin Ruby expects to find them in /usr/lib/ruby. So Cygwin wasn’t seeing rubygems, or any of the previously installed Gems.
I’m sure there’s a way to let both Ruby’s co-exist and share the same library, either through environment variables or symbolic link, but on further investigation I decided that’s not going to work out. Some Gems work or install differently (the MySQL library being one of them), so I just went and installed RubyGems again.
Rake Noop
This is something I saw on Cygwin but strangely enough not on the Windows Ruby. Trying to build a package, I got the error message:
no such option: noop
A small change to the code fixed it, adding the :noop option in fileutils.rb line 119.
Getting MySQL to work
Since Windows doesn’t include the UNIX build tools, I previously installed MySQL using the RubyForApache. With Cygwin, it’s just a matter of installing the mysql Gem and letting it build the extension library.
Before you do that, you need the MySQL client library and header files. First download the MySQL source code and select the generic package, not the Windows package, since you’re building for a POSIX environment. In the source directory run ./configure, followed by make install. I found out that I only need to run make install in the libmysql and include directories, to build the client library and install the header files. Once these two are installed, it’s as simple as:
gem install mysql
The first attempt to use MySQL failed miserably with:
No such file or directory - /tmp/mysql.sock
It turns out that connecting to localhost in the Cygwin environment attempts to use UNIX sockets. I run MySQL 4.1 as a Windows service, using NT pipes for local connections. Similar concept, but not interoperable. The quick fix is changing localhost to 127.0.0.1. With an IP address (or any name other than localhost), the client library uses TCP/IP instead.
If you don’t want to build the MySQL client libraries, you can use the pure-Ruby MySQL driver that comes with Rails. That one works out of the box, it’s just faster. It also defaults to using UNIX sockets when connecting to localhost, again just a matter of using 127.0.0.1 instead.
Â
Update: I originally reported the problem with :noop as belonging to rake.rb, when in fact the file to change is fileutils.rb. I since found out that the :noop option is present in the Windows 1.8.2 libraries, but missing in the Cygwin 1.8.3 libraries and missing from the latest CVS snapshot.
{|ihower.idv.tw| blog } » Rails on Cygwin 之Mac-like開發環境全套