Homebrew needs permissions in /usr/local and since no one else uses my laptop I have always simply done
sudo chown -R $(whoami) $(brew --prefix)
but in High Sierra, this gives
chown: /usr/local: Operation not permitted
What is the fix?
The problem kept occurring... after digging deeper I found that only uninstalling Homebrew and then re-installing it solved this issue.
Uninstall Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Then re-install it:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"