How to Install ruby mysql on Mac OS X 10.6 (Snow Leopard)

Do a quick google search for “ruby mysql mac” and you’ll find the first result:

How to install the MySQL/Ruby gem on Mac OS X Leopard

This article really helped me when I was using Mac OS X 10.5 and wanted to connect to MySQL with ruby. I just got a Macbook Pro with Mac OS X 10.6 (snow leopard) pre-installed and the method this article taught us no longer works. Do a simple test in irb and ruby will give you an error like:

>>'localhost', 'user', 'pass', 'db')
ArgumentError: wrong number of arguments (4 for 0)
     from (irb):4:in `initialize'
     from (irb):4:in `new'
     from (irb):4

After trying a lot of ways, I finally got Ruby/MySQL working on my new Mac. The article mentioned above told us to install the x86 version of MySQL and set ARCHFLAGS=”-arch i386″. But on Mac OS X 10.6 (snow leopard), we should install x86_64 version for snow leopard (Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive) and set ARCHFLAGS=”-arch x86_64″. The complete command:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
  --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \

I only tested this way to install ruby mysql on the newest Macbook Pro models with snow leopard pre-installed so not sure if it also works on old models that are upgraded to 10.6 snow leopard.

How to uninstall MySQL on Mac OS X? I’m using the method described in “Uninstalling MySQL on Mac OS X Leopard“. Yes again – this article is also for Leopard, but I used it on Mac OS X Snow Leopard with no problem.


  1. Thank you – you saved me from much frustration.

    I ran the first command with the proper architecture arguments and that did the trick.

    Uninstalling MySQL is a different issue – this might be a bit confusing leaving that as a part of the article.

  2. If you’re using RVM you willl need to specify where the ruby headers are.

    env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config –with-ruby-include=/Users/craig/.rvm/src/ruby-1.9.2-p180/

  3. Thanks. I had it installed but it was incredibly slow, for some reason replacing it with your gem install line, fixed it quickly.

    Thanks again!

  4. I ran into new issues with an upgrade to os Lion.

    This fixed it for me:

    env ARCHFLAGS=”-arch x86_64″ gem install mysql — –with-mysql-config=/usr/local/mysql/bin/mysql_config –with-ruby-include=/Users/craig/.rvm/src/ruby-1.9.2-p180/ –with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib –with-mysql-include=/usr/local/mysql/include

Leave a comment

Your email address will not be published. Required fields are marked *

Prove your intelligence before hitting * Time limit is exhausted. Please reload CAPTCHA.