The blogs, however, became obsolete quickly and even blog posts few months old don’t work with latest version of bundler. We came across this issue that kept is in a loop for a while.
Snow Leopard changed a few things with ruby and mysql gem when it came out. Most mysql installation issues are hammered out by now and are well documented.
Before you jump and execute following commands, make sure that you indeed have 64 bit mysql and 64 bit ruby on your machine. (If not, these instructions may not apply to your need).
$ file `which ruby` /Users/xxx/ruby/bin/ruby: Mach-O 64-bit executable x86_64 $ file `which mysql` /usr/local/mysql/bin/mysql: Mach-O 64-bit executable x86_64
Both installations should be Mach-O 64-bit x86_64 architecture.
In summary, installing mysql gem requires 2 things:
- Specifying architecture flags: ARCHFLAGS=”-arch x86_64″
- Specify location of mysql_config to compile agains: –with-mysql-config=/usr/local/mysql/bin/mysql_config
Prior to bundler, this is what you would do on snow-leopard to install mysql:
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
With bundler, there is no command line option that I could find that I can pass to “bundle install” command. Having been in the loop around bundler, I knew that such OS specific options don’t go in Gemfile and have to be specified in user specific files such as ~/.bundle/config file. The official website for gem-bundler doesn’t have any mention of this (is it because we need to keep things simple for people just getting upto speed with bundler?).
Bundler has a feature which allow specifying build options as documented here. So, I did this:
$ bundle config build.mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
This updated my ~/.bundle/config with proper information that it will need for “bundle install” command. It make sense to keep this in ~/ folder and not my project folder since it applies only to my environment and it applies to all projects on this machine.
With this, doing “bundle install” still doesn’t install mysql properly. Comparing this to the pre-bundler command, it solves one issue. The ARCHFLAGS still need to be available for “bundle install”. With some leap of faith, I set an environment variable to this effect:
$ export ARCHFLAGS="-arch x86_64" # should this go in my .bash_profile (so that mysql installs fine always, for all projects? # And I don't have to remember to set this each time I do a fresh bundle install.
And voila, “bundle install” installs mysql correctly.
Bundler is stable now and is making everybody’s life much much easier. It isn’t changing as fast and so this blog post won’t be obsolete too soon
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.