Installing Bundler, Rails and MySQL on OS X Snow Leopard
Sam Phillips, January 4th, 2010 11:11 pm
I’ve been feeling the love for bundler over the last week or so – if you’ve not used it before, it’s a new way to vendor gems within a ruby project that a distinct advantage over config.gem – it doesn’t suck. And it’s much better suited to deployment. I’ve already added it to a hobby rails project, a work gem project and have been working with one of our teams to get it added to a major project today. Here’s some stuff I’ve learned:
MySQL
As we all know, installing the MySQL gem on Snow Leopard required specifying the architecture under which to build – because the gem cannot work universally. Because the build is quite specific to the OS you’re working on, you have two choices when running with bundler.
Option A: bundle the gem and specify the architecture on the CLI
I’m storing (and versioning) the .gem binary files, and not files created when you run ‘gem bundle’. If you’ve got the MySQL gem cached as well, you’ll need to run ‘gem bundle’ passing a config file, something like this:
--build-options build_options.yml
Where the build_options.yml looks something like:
mysql: mysql-config: /usr/local/lib/mysql
And you’ll have to specify the architecture, bringing the whole command to:
$ env ARCHFLAGS="-arch x86_64" gem bundle --build-options build_options.yml
Instead, I chose to go with:
Option B: Use ruby’s MySQL gem
This might be your rvm ruby, or your system. Either way, if you want your app to be able to access the MySQL gem, but not to bundle it, add the following to your Gemfile:
gem 'mysql', :bundle => false
And run ‘gem bundle’ again to regenerate the environment file. It seems that, depending on your system, bundler will sometimes fall back to ruby’s own gems automatically, and sometimes it won’t. For me, I was getting ‘no such file to load – mysql’ until I added the config to the Gemfile.
Btw, adding ‘disable_system_gems’ to your Gemfile when you’re calling a system gem will not work. Perhaps this is obvious – I had assumed (perhaps mistakenly) that the behaviour would only disable the graceful ‘fallback’ to the system; in fact it seems to block even explicit calls to the system.
Changing the vendor directory with Rails
The current default for the bundler gem cache is vendor/gems – this is the same as Rails 2.x and can mean config.gem tries to deal with them. Do yourself a favour and add the following to your Gemfile:
bundle_path "vendor/bundler_gems"
Or similar… this helped me with a few weird Rails issues.
Helpful stuff on bundler:
The peeps in #carlhuda on irc.freenode.net were also very helpful when I was struggling with this.









2 Comments:
Thanks for linking to rails template article. I’m glad you found it helpful. Another way to get around the ARCHFLAGS issue is to set the environment variable in your rc file (.bashrc/.zshrc/etc.). That’s what I’ve done – it seems to work well.
Comment by Tom Ward — January 11th, 2010 @ 3:53 pmFound that after I wrote this! You can also add a .rvmrc config in ~/ as well; not tried this yet though.
Comment by Sam Phillips — January 11th, 2010 @ 4:53 pmLeave a comment