[Mac] How to Fix brew Command Not Working in Yosemite

Tadashi Shigeoka ·  Sun, April 19, 2015

When trying to execute the brew command in Mac OS X Yosemite, an error occurred.

Error Content

% brew -h
/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 21: /usr/local/Library/brew.rb: Undefined error: 0

Steps to Restore brew Command

First, change the ruby path from 1.8 to current as follows:

git diff

diff --git a/Library/brew.rb b/Library/brew.rb
index 4fa22b4..ee05650 100755
--- a/Library/brew.rb
+++ b/Library/brew.rb
@@ -1,4 +1,4 @@
-#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
+#!/System/Library/Frameworks/Ruby.framework/Versions/current/usr/bin/ruby -W0
 # encoding: UTF-8
 
 std_trap = trap("INT") { exit! 130 } # no backtrace thanks

Next, navigate to the brew git repository and commit the changes:

cd $(brew --prefix)
git add .
git commit -m 'Change the path for ruby'
brew update

If you don’t commit the git changes first, you’ll get an error when running brew update:

% brew update

error: Your local changes to the following files would be overwritten by merge:
  Library/Formula/mongodb.rb
Please, commit your changes or stash them before you can merge.
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

When brew update conflicts severely, you can discard local changes:

git reset --hard HEAD
git merge -Xtheirs origin/master

And that’s OK.


Reference Information

That’s all from the Gemba.