24 September 2007

Installing Ruby MySQL Gem with MacPorts MySQL

Blogging this more for my own record, but maybe others will find it useful... Tonight I was having a hard time getting the MySQL Ruby Gem installed on a new MacBook Pro. I have installed Ruby, Rails, RubyGems, MySQL, etc. via MacPorts (or via the Ruby that was installed via MacPorts). Anyway, this is the command that finally got it to work:

sudo gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config


Update: as I mention in my comment below (updating here in case folks don't read the comments), when doing this on Leopard/MacOS X 10.5, I needed to change it to:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

19 comments:

Anonymous said...

I had the same problem and googled "macports mysql gem" and your post was first on the list. I'm sure others will find this helpful too. Works perfectly. Thanks!

Anonymous said...

it work!!

Mark Holton said...

this worked perfectly for me, many thanks.

Chris said...

Note, when doing this on Leopard/MacOS X 10.5, I needed to change it to:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 \
--with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

Robert Dempsey said...

Thanks for the heads up on the gem install, and thanks for adding in the "arch" item as well - that got it for me on Panther.

Unknown said...
This comment has been removed by the author.
Anonymous said...

Don't know why my install needed a slightly different version: sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-include=/usr/local/mysql/include --with-mysql-lib=/usr/local/mysql/lib --with-mysql-config=/usr/local/mysql/bin/mysql_config

Anonymous said...

Thanks a ton, this was very helpful.

Anonymous said...

i luv u anonymous man

Anonymous said...

worked great. cheers.

Anonymous said...

To anonymous who used the /usr/local/... tree, my guess is that you previously had the binary mySQL from mySQL installed as that sits in the /usr/local/mysql directory. Otherwise, a fresh install of mySQL on a new mac would not have any files there.

Anonymous said...

Very helpful post. Thx a lot!

Anonymous said...

Worked perfectly for Leopard! Thx

Anonymous said...

excellent stuff, solved the problem for me.

nice blog my the way, you've got some impressive stuff there.


John.

charliepark said...

Thank you for posting this!!! Hugely helpful.

Law said...

yes, worked. also if you get an error after the gem installs properly like this

dyld: Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib

do one of these

sudo install_name_tool -change /usr/local/mysql/lib/mysql/libmysqlclient.15.dylib /usr/local/mysql/lib/libmysqlclient.15.dylib /opt/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

and you're golden.

Anonymous said...

Thank you!

Anonymous said...

Awesome! Just what I needed! Thanks so much!!!

Paul Bjergsted Jensen said...

Awesome tip, thanks