Ruby, Leopard and gems
Thursday, October 25th, 2007In case you have been sleeping in the same cave as Osama Bin Laden, Apple’s new OS X Leopard includes Ruby as a first-class language.
But Apple’s effort to make the language and all it’s extensions universal binaries can cause you some trouble when installing gems that require compilation.
If you’re installing on an Intel machine and see an error like “ld: symbol(s) not found for architecture ppc”, you probably are installing a gem that requires an external library, for which you only have the i386 version. This is a typical situation when installing mysql (as noted in the troubleshooting page of the MacOSForge wiki for Ruby).
After trying several variations, I came out with this solution:
If your installation command was
sudo gem install mysql
you need to run it as
sudo bash -c "ARCHFLAGS='-arch i386' gem install mysql"
sudo env ARCHFLAGS="-arch i386" gem install mysql
There you go… that should be all you need to install the mysql gem on Leopard against MySQL’s prepackaged binaries.
UPDATE: The troubleshooting page has been updated to include an alternative: using “sudo -s” to start a root shell. I still like my one-liner better :-)
UPDATE 2: Using env instead of bash is slightly cleaner.
UPDATE 3: MySQL still has some problems, because the library is pointing to the wrong direction. The quick solution is to create a link to the right place:
sudo ln -s /usr/local/bin/mysql/lib /usr/local/bin/mysql/lib/mysql