Unfortunately for me, every once in a while I have to worry about software dependencies. The issue crops up every year or so when there is either a security patch that we (work) need to install or an upgrade we want to attempt. As I get older I’ve become slightly less enthusiastic about upgrading often or at least upgrading quickly. So it was with some trepidation that I removed MacPorts from my MacBook Pro today and decided to give Homebrew a shot.
The good news: It pretty much works for me.
The bad news: It pretty much failed for me within a few hours of installing it.
Failed may be a bit harsh. At work we use a specific version of mysql and that version is compiled with specific options that we require. Homebrew doesn’t make it immediately obvious how you go about requesting a specific version of a package nor how you specify any options for the package when it is built.
I’m not going to bother going over the basics of getting Homebrew up and running as there are already a number of resources for such things. Dr. Google is your friend (or Dr. Bing, or whomever you visit when you are in need). But I will share how to get a Homebrew formula (the recipe for building packages) to do what you want in a few simple steps.
Altering a Homebrew recipe
At first I thought it might be necessary to fork the git repository of homebrew or at least make a fork, branch, or copy of the mysql.rb formula. But, that would have been a lot of overhead for simply altering some build options. Also, the specific set of options I need are probably only relevant to me on this particular project. They certainly would not be the correct options for everyone.
To alter the options one can simply edit the Ruby formula file in brew --prefix/Library/Formula. If you installed Homebrew into /usr/local (which the authors make quite clear that they would very much like you to do) then the path would be: /usr/local/Library/Formula. For example, to edit the mysql build options:
vim `brew --prefix`/Library/Formula/mysql.rb
Look for the array of configure_args. Edit them to your heart’s content.
brew uninstall mysql
brew install mysql
Done! In my case in step two I changed the —with-plugins option to supply the plugins that my mysql install requires.
Alternatively, you could also make a copy of mysql.rb (I actually made a copy of the file myself before editing away). In that case you’d just need to change the class declaration at the top of the file. For example, if you name the file mysql-myCompany.rb then on line 3 you’d change:
class Mysql <Formula
to
class MysqlMyCompany < Formula
To ensure your new formula is in place run:
brew info mysql-myCompany
To finish it off you’d need to:
brew uninstall mysql
brew install mysql-myCompany
My sentiment is this: You own the formula directory. It’s on your hard drive, is it not? Do with it as you please.
The drawback of course is that when updating homebrew there may be a conflict on the file or it may just be replaced. I’m hoping since it is just git underneath that the brew update command will give me some way to reconcile the problem. Maybe I’m blindly optimistic. But as I mentioned you can always create your own file if you are concerned.
There also appears to be a HOMEBREW_LIBRARY_PATH environment variable that you could set to temporarily use your own Library and the formula within. Haven’t tried that yet but it is definitely worth a look. Especially if you just want to create your own formula and test it out before embarking on contributing to the de-facto Library.
launchctl is persistent
There were a few nasty issues for me after installing mysql. First, the instructions helpfully provide the command for adding mysql to launchctl so that OS X will start mysql when you boot:
launchctl load -w