Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX Homebrew error: uninitialized constant MACOS

Tags:

macos

homebrew

I've searched around a bit and can't seem to find any record of anyone else with this problem.

Whenever I try to run

$ brew update

I am rewarded with

/usr/local/bin/brew:34: uninitialized constant MACOS (NameError)

This isn't my machine and I normally develop on Linux systems so this is all a bit odd to me.

Any help would be greatly appreciated! Please tell me if there is any additional info I should provide. Again, I'm not used to homebrew or OSX.

EDIT at the request of JameA

xiao:~ patrick$ brew doctor
/usr/local/bin/brew:34: uninitialized constant MACOS (NameError)
xiao:~ patrick$ brew --config
/usr/local/bin/brew:34: uninitialized constant MACOS (NameError)

...Not sure I like this whole "here, use this macbook for the project, it works better" thing...

like image 477
pdel Avatar asked Jun 23 '12 22:06

pdel


1 Answers

I'm pretty sure the root cause of this is a failed upgrade attempt to Homebrew 0.9.5 from a much earlier version. Basically, if you run brew update as opposed to sudo brew update a portion of files are updated, while others are not. Here's what worked for me:

  1. Edit /usr/local/bin/brew (it's just a Ruby file, not a compiled binary, so any text editor will do). You'll find a block like:

    if MACOS and MACOS_VERSION < 10.5
      abort <<-EOABORT.undent
        Homebrew requires Leopard or higher. For Tiger support, see:
        https://github.com/mistydemeo/tigerbrew
      EOABORT
    end
    

    Comment this out. Even if you don't know Ruby, you can probably intuit what this is doing—it's checking to see if you have a current version of OSX. Assuming that you do in fact have this version, this sanity check isn't necessary. Brew is still broken, but at least now it will load far enough to give error messages.

  2. Run sudo brew update, spoiler alert: it fails, but this time with a meaningful error message:

     $ brew update
     error: Your local changes to the following files would be overwritten by merge:
     [giant list of files here]
    

    Well, today I learned that brew update is just a wrapper for git pull because anyone who has worked with git knows that error message. We can fix this too.

  3. Switch into the homebrew git repository with cd /usr/local and give the command git reset --hard FETCH_HEAD. This piece found here.

  4. Give the command sudo brew update. Homebrew should now update successfully and work properly!

Once the system is working again, you can actually kind of see why an error like this would have occurred. For one, usr/local/bin/brew has been completely rewriten and isn't even Ruby anymore, and most of its configuration has been moved into /usr/local/Library/brew.rb which no longer uses the constants MACOS or MACOS_VERSION constants, as they have been replaced by the more object oriented OS.mac and MacOS.version.

like image 112
Matt Korostoff Avatar answered Oct 21 '22 18:10

Matt Korostoff