183

I faced some issue with Homebrew. I upgraded to Yosemite. After the upgrade, homebrew seems to be broken.

I would run any brew command and get this error

/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

How to resolve it?

  • I just upgraded from Mac OS X 10.8 to 10.10 (Yosemite), and homebrew works fine after the upgrade. Either this problem was fixed, or there was something different about my OS upgrade compared to everyone else posting here. – Yitz Apr 08 '15 at 14:50

5 Answers5

240

I decided to look this up and found that there is an issue. The issue is closed but it is not possible to simply run brew update because you will still get the same error.

So here is what you need to do:

cd /usr/local/Library
git pull origin master

In case you have changes in the directory (/usr/local/Library), the git pull will throw an error. In that case, you'll have to fetch the master branch and set it forcibly as master:

git fetch --all
git reset --hard origin/master

This will upgrade your homebrew and you can use brew again.

If you installed Homebrew as a non-root user, you'll need to cd to /Users/yourusername/homebrew/Library instead of /usr/local/Library.

  • 20
    yet another reason I love having a package manager built on git :) – spinlock Nov 03 '14 at 17:48
  • 3
    Exactly. Love software that simply runs from source and upgradable through git pull – Ranjith Ramachandra Nov 04 '14 at 07:34
  • Aw shucks I think we should revert back to the Microsoft Windows way - and drop into the maelstrom of the registry. – WestCoastProjects Nov 19 '14 at 00:29
  • 7
    Weird, I'm getting this fatal: Not a git repository (or any of the parent directories): .git – Gabriel R. Nov 24 '14 at 10:48
  • Thats not right. Are u sure the path is correct? – Ranjith Ramachandra Nov 24 '14 at 11:49
  • 2
    I'm getting this error: error: cannot open .git/FETCH_HEAD: Permission denied – sixty4bit Nov 25 '14 at 03:40
  • 6
    Try sudo git pull origin master – Ranjith Ramachandra Nov 25 '14 at 04:10
  • 1
    @GabrielR. I also get. How did you manage with it? – Dejel Nov 26 '14 at 19:20
  • Another problem that can be fixed by going to my local library. Thanks! – Renee Dec 22 '14 at 06:37
  • I also had to reset Git: git reset --hard HEAD git clean -f -d git pull – Philippe Monnet Jan 04 '15 at 18:25
  • You are da man!!! – ninja08 Feb 19 '15 at 20:40
  • You are da ninja!!! – Ranjith Ramachandra Feb 20 '15 at 05:29
  • If you have an old version of brew you might have a git repo in /usr/local/Library yet. Just edit brew.rb and change "1.8" to "Current" in the first line. Then simply run brew update again and it will update to the latest version (the git repo will be created at the time). – Alexis Jul 12 '15 at 19:52
  • In part, this solution also fixed a problem after upgrading from Yosemite to El Capitan. The error: Could not restore untracked files from stash Error: Failure while executing: git stash pop --quiet. First do sudo chown -R $(whoami):admin /usr/local and then apply this solution. – Christopher Oct 01 '15 at 15:52
  • 1
    Not sure if anyone else faced this issue, but for some reason the git repository for homebrew on my system was located at /Users/username/homebrew instead of /Users/yourusername/homebrew/Library (also updating brew.rb was a quick fix too). – matt snider Dec 06 '15 at 18:42
  • I had to go up one level from /usr/local/Library and also remove modified files: (danger) git fetch origin master; git add --all . ; git reset --hard origin/master; Then I was able to merge in the latest as you said: git pull origin master. I was concerned about the git repo being on the share directory. But I guess that is why Homebrew likes to own all your installs. Beware if you have non-Brew installed stuff. – Doug Mar 06 '16 at 20:43
48

I found this solution:

That link describes it well, but in case the link goes down, here is what you need to do: Type these commands into your Terminal:

cd /System/Library/Frameworks/Ruby.framework/Versions
sudo ln -s Current 1.8
brew update
sudo rm 1.8
22

The version and location of Ruby changed with the new Mac OS X version.

To fix this in a generic way, edit /usr/local/Library/brew.rb.

On the first line, replace 1.8 with Current, i.e. from:

#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0 

to:

#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
  • This breaks brew update because you now have an uncommitted change. – Cam Price-Austin Nov 28 '14 at 00:58
  • 1
    …but to do brew update one has to apply the fix I suggested.I never used brew update until now, so I didn't even have the repo initialized. Can't remember how I even installed it. – Gabriel R. Nov 28 '14 at 11:18
3

If you fix the ruby problem and then hit a problem where you are told that the system thinks you are running tiger or an older release, the fix for that is here

Drux
  • 131
1

I first tried the highest rated answer an then hit another issue. After that I kind of gave up on fixing it since I had just a couple packages installed. Maybe others are in this boat as well.

While these are all excellent answers, for me it was simpler to just to re-install brew.

First, I ran the instructions on:

http://brew.sh/

which directed me to first uninstall, and printed a command line. I ran that command line to uninstall, then re-installed, and everything was fine.

I don't want to print the specific commands, as they tend to change a bit as brew adjust how things are installed.

dpb
  • 301