久しぶりにHomebrewをupdateしたら以下のようなエラーがでて失敗し、全てのbrewコマンドが使えなくなった時の対処法です。原因は特定してないけど、おそらくOSをEl Capitanにアップデートしたせい。
takezoux2$ 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>'
1: /usr/local
を元の状態に戻す
上記エラーが出てしまうと、brewのコマンドが全て使用できなくなるので、brewのディレクトリを元の状態に戻します。
cd /usr/local
して、git reset --hard && git clean -df
を実行し、ファイルを全て巻き戻して下さい。
2: /usr/local
の権限を変更
brew doctorで以下のようなエラーが出る場合、
takezoux2$ 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: 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.
コマンド
sudo chown -R $(whoami):admin /usr/local
(${whoami}の部分もそのままでOK)を実行して権限を変更します。
3: brew update
する
後は、updateすれば成功するはずです。