Original Answer
The problem mainly occurs after updating OS X to El Capitan (OS X 10.11) or macOS Sierra (macOS 10.12).
This is because of file permission issues with El Capitan’s or later macOS’s new SIP process. Try changing the permissions for the /usr/local
directory:
$ sudo chown -R $(whoami):admin /usr/local
If it still doesn’t work, use these steps inside a terminal session and everything will be fine:
cd /usr/local/Homebrew
git reset --hard origin/master
brew update
If /usr/local/Library/Homebrew
doesn’t work, try /usr/local/Homebrew
. The problem might be that Homebrew is outdated.
Apr 2021 Update
The command above doesn’t work for macOS High Sierra or above, as explained in this GitHub issue. You have to run this instead:
sudo chown -R $(whoami) $(brew --prefix)/*