Brew Problems on Mac

On my mac OSX Yosemite.

when I do a brew update

error: unable to unlink old 'bin/brew' (Permission denied)
error: unable to unlink old 'share/man/man1/brew.1' (Permission denied)

OK. So I do a sudo brew update

MacBook-Pro:bin$ sudo brew update
Password:
Error: Cowardly refusing to `sudo brew update`
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

So it doesn't let me run the update in any way.


Solution 1:

Try this:

sudo chown -R $USER /usr/local; brew update

Solution 2:

The homebrew has a doctor command to help with documenting any internal errors. I would start there rather than guessing what is happening.

brew doctor

Next, you could re-install the latest brew over the top of what you have if you can't get a reliable output from the doctor. It won't replace anything you downloaded from brew already - it will just get you a stable install package and the ability to take the next step (perhaps). Usually what happens is some other program or package thinks it needs to change all the permissions and ownership in /usr/local and that harms the assumptions that the brew tool makes.