RVM Ruby 1.9 and the MySQL Gem — Friends at last on x86_64
by Erik Runyon on November 13, 2009
One of our production Rails apps is running on Ruby 1.9. The problem this introduces is that our dev environments must be able to run multiple versions of Ruby side-by-side. There’s nothing unique about this, it comes with the Ruby/Rails territory. After upgrading to Snow Leopard, I decided to give Ruby Version Manager a try. The install of RVM and the subsequent Ruby installs were a breeze. However, when it came time to install the MySQL gem, I ran into a brick wall. No matter what I tried, I kept getting install errors.
I’m running the standard MacOSX package install from mysql.com (Mac OS X 10.5 x86_64). I tried setting my ARCHFLAGS to the correct architecture, pointing to the correct config, and nothing helped. After Google turned up nothing, I decided to bother the nice folks in the #rvm channel. There I was given a handy little tip that goes as follows:
- Uninstall the version of Ruby you’re trying to install the MySQL gem on
- place the following in your ~/.rvmrc file:
rvm_archflags="-arch x86_64"
- Reinstall Ruby using RVM
- Install the ruby gem:
export ARCHFLAGS="-arch x86_64" ; gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
(use the correct path to your MySQL config file. If you installed mysql with MacPorts, it will be in /opt somewhere).
The problem turned out to be that RVM was not installing the x86_64 version of Ruby 1.9. And if Ruby’s architecture doesn’t match MySQL’s, then you have problems. Once they match, then it’s back to Ruby bliss.
2 comments
That is correct. The biggest concept to take away from this is that mysql architecture must match the selected ruby’s architecture so you have to install/compile both to the same arch.
You can find out the architecture of each by inspecting the output of:
file $(which mysql)
file $(which ruby)
Also be aware that there were just two bugfixes in building rubies:
* it now honors (again) the configure flags passed in on the command line -C –enable-shared,–with-iconv-dir=………..
* It now specifies configure flags –host and –build on OSX in order to ensure that it will properly build as x86_64 or i386.
Thank you for using rvm !
~Wayne
by Wayne E. Seguin on November 14, 2009 at 6:21 am. #
A Very interesting post . Any time i read your website i find a unique view. Furthermore , as a new developer, i have to say that the structure of your blog rocks . Could you post some information regarding the theme ? .
Thanks .
by Stevie Oxborough on September 13, 2010 at 5:19 am. #