Fixing Homebrew on OS X Yosemite

Homebrew is “The missing package manager for OS X”. It’s pretty great. Unfortunately, upgrading to OS X Yosemite might break it, as it did for me.

There are several paths for fixing it, depending on when you realize it’s broken. Here are a few possible fixes that you can use.

If you just want the bottom line, here it is:

  1. If you still haven’t upgraded to OS X Yosemite, run brew update before the OS X upgrade.
  2. If you already upgraded OS X and your Homebrew is broken, run git pull from /usr/local, and then run brew update.

Read on for more details on my experience with the break and fix.

When I started using OS X, I knew it’s based on Linux. Having some experience with Linux (Ubuntu and such), I expected OS X to bake in package management system, like apt-get, RPM, or yum.

I was disappointed to find out it didn’t have any. Shortly after that, I discovered Homebrew, the self-described “missing package manager for OS X”. It was what I was looking for. Just brew install whatever, and it (mostly) works.

Homebrew is the missing package manager for OS X that I was looking for

OS X Yosemite breaks Homebrew

After upgrading to OS X Yosemite, it took a week or two until I wanted to install something (coreutils to be exact) with Homebrew. Alas! I found it broken, crying in a dark corner!

Here’s the symptom I observed:

itamar@legolas ~ $ brew install coreutils
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 26: /usr/local/Library/brew.rb: Undefined error: 0

WTF? What happened to you, ruby?!

Looks like brew is looking for ruby 1.8, which is not there. Lets ask ruby what it thinks about it:

itamar@legolas ~ $ which ruby
/usr/bin/ruby
itamar@legolas ~ $ ruby --version
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

Indeed, 1.8 is out of the window. At this stage I assume that the OS X upgrade brought in the shiny ruby 2.0, but Homebrew had 1.8 hardcoded some where.

Upgrading OS X to Yosemite before updating Homebrew results a broken Homebrew…

My first fix attempt

The error originated from /usr/local/Library/brew.rb, so I create a backup copy, and try editing the offender to use the new ruby:

itamar@legolas ~ $ sudo cp /usr/local/Library/brew.rb /usr/local/Library/brew.rb.bak
itamar@legolas ~ $ sudo nano /usr/local/Library/brew.rb
# ... modify the first line to "#!/usr/bin/env ruby -W0" instead of "#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0"
itamar@legolas ~ $ brew install coreutils
==> Installing coreutils dependency: xz
==> Downloading http://fossies.org/linux/misc/xz-5.0.5.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/xz/5.0.5
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/private/tmp/xz-ms6a/xz-5.0.5':
configure: error: C compiler cannot create executables
See `config.log' for more details
Error: Homebrew doesn't know what compiler versions ship with your version
of Xcode (6.1). Please `brew update` and if that doesn't help, file
an issue with the output of `brew --config`:
  https://github.com/Homebrew/homebrew/issues

Note that we only track stable, released versions of Xcode.

Thanks!

READ THIS: https://github.com/Homebrew/homebrew/wiki/troubleshooting

Well, my fix worked partially. ruby is no longer a problem, but there are other problems. At least now Homebrew tells me it wants me to update it, so why not listen?

itamar@legolas ~ $ brew update
error: Your local changes to the following files would be overwritten by merge:
     Library/brew.rb
Please, commit your changes or stash them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

Ugh. I can’t update with uncommitted changes. I can’t update without the changes. I don’t want to commit my changes because they might conflict with the upstream changes. What to do??

The simple answer would be to revert my local changes, and manually run the git pull -q origin refs/heads/master:refs/remotes/origin/master that failed. That would have probably worked.

My second fix attempt (that worked!)

Instead, I found the commit that fixed it in the homebrew GitHub, and applied the change they did instead of my change. I committed this locally, using the same commit message, and then I ran brew update.

itamar@legolas ~ $ cd /usr/local/Library
itamar@legolas Library (master) $ cp brew.rb brew.rb.myfix
itamar@legolas Library (master) $ git checkout -- brew.rb
itamar@legolas Library (master) $ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

     brew.rb.bak
     brew.rb.myfix

nothing added to commit but untracked files present (use "git add" to track)
itamar@legolas Library (master) $ nano brew.rb
# .... replicate the change from https://github.com/Homebrew/homebrew/commit/1bbcc4b5110f5a0573dfc78175d05fe454bbbda0 ....
itamar@legolas Library (master) $ git commit -a -m "Switch to \"Current\" Ruby framework symlink"
[master 7676006] Switch to "Current" Ruby framework symlink
1 file changed, 1 insertion(+), 1 deletion(-)
itamar@legolas Library (master) $ brew update
Auto-merging Library/brew.rb
...
...
...
==> Deleted Formulae
agedu            aws-iam-tools         connect           gfortran          hugs98            libdlna         openfst           rcssmonitor     tetgen
aplus            cantera         dart           gnunet          iulib            libspotify         pan                saga-core          texmacs
appledoc       catdoc         drush           gromacs          jstalk            metalua         pjsip           shark          tmap
appswitch       clam              electric-fence    haskell-platform     justniffer       mpio              play           solfege          ushare
asymptote       cloudfoundry-cli  fceux           hllib          kismet            msgpack-rpc         rcsslogplayer     sundials
itamar@legolas Library (master) $ cd
itamar@legolas ~ $ brew install coreutils
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/coreutils-8.23_1.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring coreutils-8.23_1.yosemite.bottle.1.tar.gz
==> Caveats
All commands have been installed with the prefix 'g'.

If you really need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:

    PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:

    MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"

==> Summary
/usr/local/Cellar/coreutils/8.23_1: 214 files, 10M

Great success!

No Comments Yet.

Leave a Reply