brew updateでエラーになった時にやったこと

brew update

したら次のエラーが出た。

error: unable to unlink old 'share/man/man1/brew.1' (Permission denied)
Error: Failure while executing: git pull --ff --no-rebase --quiet origin refs/heads/master:refs/remotes/origin/master

状況の確認のため

brew doctor

を確認してみる。

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: /usr/local/bin isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/bin

Warning: /usr/local/share isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/share

Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:
    /usr/local/share/man
    /usr/local/share/man/man1

Warning: You have uncommitted modifications to Homebrew
If this a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
    cd /usr/local/Library && git stash && git clean -d -f

指示されているコマンドを実行する

sudo chown ユーザー名 /usr/local/bin
sudo chown ユーザー名 /usr/local/share
sudo chown ユーザー名 /usr/local/share/man
sudo chown ユーザー名 /usr/local/share/man/man1
cd /usr/local/Library && git stash && git clean -d -f