homebrew

Homebrewを久々にupdateしたら出来なかった時の対処法

More than 1 year has passed since last update.

久しぶりに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すれば成功するはずです。