1. Nov 6th, 2005

    Setting up Ruby + Gems on CygWin

    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.

    1. Nov 7th, 2005

      Jim Weirich

      Why was noop required in rake.rb? That sounds like a change to rake itself, as opposed to the Rakefile.

    2. Nov 8th, 2005

      Assaf

      first apologies, the problem is not in rake.rb itself but in fileutils.rb, line 119:
      http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/fileutils.rb?rev=1.67

      I traced the problem from rake, since rake calls each of the fileutils functions passing the option :noop.

      each function calls fu_check_options to validate the options, and cd fails since it forgets to pass :noop to fu_check_options.

    3. Mar 21st, 2007

      sebastien

      Hi thanks for your tips for mysql/cygwin setup.
      Actually i am working with a remote database server. Is there a way of still using cygwin ? therefore I can not use the 127.0.0.1 hack.

      thanks

      sebastien

    4. Mar 22nd, 2007

      Assaf

      You only need the 127.0.0.1 hack when running MySQL server locally to force it to use IP instead of sockets. When you’re running MySQL remotely and give an IP address (or host name) it will always use IP.

    5. Apr 9th, 2007

      nick

      Hey there- I tried this but I get a big ugly error message. I’m using cygwin behind a proxy (but that doesn’t seem to be the problem). any advice from yourself or the community would be helpful! thanks! – nick

      $ gem install mysql
      Select which gem to install for your platform (i386-cygwin)
      1. mysql 2.7.3 (mswin32)
      2. mysql 2.7.1 (mswin32)
      3. mysql 2.7 (ruby)
      4. mysql 2.6 (ruby)
      5. Skip this gem
      6. Cancel installation
      > 3
      Building native extensions. This could take a while…
      ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
      ERROR: Failed to build gem native extension.

      ruby extconf.rb install mysql
      checking for mysql_query() in -lmysqlclient… no
      checking for main() in -lm… yes
      checking for mysql_query() in -lmysqlclient… no
      checking for main() in -lz… yes
      checking for mysql_query() in -lmysqlclient… no
      checking for main() in -lsocket… no
      checking for mysql_query() in -lmysqlclient… no
      checking for main() in -lnsl… no
      checking for mysql_query() in -lmysqlclient… no
      *** extconf.rb failed ***
      Could not create Makefile due to some reason, probably lack of
      necessary libraries and/or headers. Check the mkmf.log file for more
      details. You may need configuration options.

      Provided configuration options:
      –with-opt-dir
      –without-opt-dir
      –with-opt-include
      –without-opt-include=${opt-dir}/include
      –with-opt-lib
      –without-opt-lib=${opt-dir}/lib
      –with-make-prog
      –without-make-prog
      –srcdir=.
      –curdir
      –ruby=/usr/bin/ruby
      –with-mysql-config
      –without-mysql-config
      –with-mysql-dir
      –without-mysql-dir
      –with-mysql-include
      –without-mysql-include=${mysql-dir}/include
      –with-mysql-lib
      –without-mysql-lib=${mysql-dir}/lib
      –with-mysqlclientlib
      –without-mysqlclientlib
      –with-mlib
      –without-mlib
      –with-mysqlclientlib
      –without-mysqlclientlib
      –with-zlib
      –without-zlib
      –with-mysqlclientlib
      –without-mysqlclientlib
      –with-socketlib
      –without-socketlib
      –with-mysqlclientlib
      –without-mysqlclientlib
      –with-nsllib
      –without-nsllib
      –with-mysqlclientlib
      –without-mysqlclientlib

    6. Apr 9th, 2007

      Assaf

      Nick,

      Make sure you have the MySQL client libraries installed, installing the MySQL server itself is not enough.

    7. Apr 14th, 2007

      Byron

      Nick, I had the same problem as you. I got exactly the same error messages as you. The solution was to symbolically link the lib and include directories to /usr/local/lib/mysql and in /usr/local/include/mysql, respectively.

    8. Apr 27th, 2007

      chip

      apt-get install libmysqlclient15-dev

      is what worked for me.

    9. May 10th, 2007

      {|ihower.idv.tw| blog } » Rails on Cygwin 之Mac-like開發環境全套

      [...] localhost 會連到 cygwin 的 MySQL 而不是 windows 的 MySQL,拜過G社大神後,找到的解法非常簡單,只要改連 127.0.0.1即可 (rails 的 database.yaml 把 localhost 改成 127.0.0.1 [...]

    10. Sep 23rd, 2007

      Matt

      I downloaded the MySQL source and ran ./configure and make install successfully. I too got the tmp/mysql.sock error but I changed localhost to 127.0.0.1 in my rails app database.yml file – and voila, my app runs fine.

      However if I want to connect to the MySQL monitor in the cygwin shell (“$ mysql -u root”), I still get the error “ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”. So my rails app can connect successfully using the the config from the database.yml file, but command line cannot.

      So how do I address this, or where do I make the config change to affect cygwin’s connection to MySQL?

      Thanks,
      Matt

    11. Sep 23rd, 2007

      Assaf

      Matt,

      mysql -h localhost

      I don’t know where you can find a file to configure this by default, check out the MySQL documentation.

    12. Feb 22nd, 2008

      G

      Thanks for approving the comment that mentioned ‘where’ you changed the definition of localhost to 127.0.0.1 — that is, in your app’s database.yml file. I’m temporarily sane again. :)

    13. Mar 16th, 2008

      MetaSpring

      I was thinking of setting CygWin up so that I could run backgroundRB on my windows machine. Right now I am developing a backgroundrb app on our development server using Samba.

    Your comment, here ⇓