Back at the start of April I wrote [mysql2 ruby gem and Mac OS X: image not found](http://samuel.kadolph.com/2011/04/mysql2-gem-and-mac-os-x-image-not-found/) to deal with the extremely relative path to `libmysqlclient.16.dylib`. I had said I would prefer not putting `libmysqlclient.16.dylib` in `/usr/lib` but I couldn’t find a dylib path that ruby uses. That is until today when I decided to try again.
I found `libexecdir` in `RbConfig::CONFIG` which is the directory where ruby can load dylib files from.
libexecdir=$(ruby -rrbconfig -e ‘puts RbConfig::CONFIG[“libexecdir”]’)
sudo mkdir -p $libexecdir
sudo ln -s /usr/local/mysql/lib/libmysqlclient.16.dylib $libexecdir
Now ruby can load `libmysqlclient.16.dylib` without putting it in `/usr/lib`.
I forgot to mention it in the first post but if your ruby wants `libmysqlclient.18.dylib`, just replace the 16 with 18. Same with any other number.