久しぶりに Homebrew を使ってインストールしようとしたら、うまく動かなくなっていました。
$ brew update
warning: unable to unlink CONTRIBUTING.md: Permission denied
warning: unable to unlink SUPPORTERS.md: Permission denied
fatal: cannot create directory at '.github': Permission denied
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
$ sudo brew update
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mach (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/Homebrew/extend/pathname.rb:2:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/Homebrew/global.rb:3:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/brew.rb:15:in `<main>’
Permission denied とか出ていて、何が起きたのかよくわからなかったので色々調べていたら、OS X を El Capitan にするときに SIP の影響で「Homebrewを先にインストールしておけ」という記事を思い出しました。なのでそちら方面で調べていたら、/usr/local のパーミッションの修正で直りました。
$ ls -la /usr/local
total 96
drwxr-xr-x 18 root wheel 612 10 17 04:41 .
所有者が root になっていたので自分自身に修正。
$(whoami)
は fish とかだと動かないので一旦 bash などへ
$ sudo chown $(whoami):admin /usr/local
$ ls -la /usr/local
total 96
drwxr-xr-x 18 kazuya admin 612 10 17 04:41 ./
手動でHomebrewを更新。
$ cd /usr/local/Library/Homebrew
$ git pull -q origin refs/heads/master:refs/remotes/origin/master
正しく動くようになりました。
$ brew update
Already up-to-date.
追記: 2016-02-28
今日別のマシンで試したらこんな素敵なエラーが出ました。
$ brew update
Error: The /usr/local directory is not writable.
Even if this directory was writable when you installed Homebrew, other
software may change permissions on this directory. Some versions of the
"InstantOn" component of Airfoil are known to do this.
You should probably change the ownership and permissions of /usr/local
back to your user account.
sudo chown -R $(whoami):admin /usr/local