MacBook Airでhomebrewが壊れた


久しぶりにMacBookでブラウザ以外を動かそうと思って`brew`の更新をしようとしたらしばらく何も使ってないのにエラーorz
こんな壊れる物なん？

```
$ brew update
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
```

しょうがないので最初からインストール

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
```

そしたらふるいの消せよ的なメッセージがｗ

```
$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
```

`rm`はうまく動いているだろうけど`brew cleanup`で同じようにエラーになってるっぽい
大丈夫かいな

とりあえず、もう一回

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
You have not agreed to the Xcode license.
Before running the installer again please agree to the license by opening
Xcode.app or running:
    sudo xcodebuild -license
```

メッセージが変わった。今度は`xcode`

```
$ sudo xcodebuild -license

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:

    :
  <中略>
    :
```

キーを適当に叩いて、最後に`agree`を叩いて再再インストール

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/homebrew/': SSLRead() return error -9806
Failed during: git fetch origin master:refs/remotes/origin/master -n
```

今度は動いてるっぽいけどＳＳＬエラー？

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
```

また消すのどうなってるのこれ？

```
$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
```

やっぱりエラーになるよね？

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 240663, done.
remote: Total 240663 (delta 0), reused 0 (delta 0), pack-reused 240663
Receiving objects: 100% (240663/240663), 33.71 MiB | 442.00 KiB/s, done.
Resolving deltas: 100% (179175/179175), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 3e7fe5b influxdb 0.9.0-rc19 (devel)
==> Installation successful!
==> Next steps
Run `brew help` to get started
```

再度・・・あ、`RETRUN`さっきは押してなかったその違い？
今度は正常に入ったっぽい

```
$ 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: Broken symlinks were found. Remove them with `brew prune`:
  /usr/local/bin/7z
  /usr/local/bin/7za
  /usr/local/bin/7zr
  /usr/local/bin/bmp2tiff
  /usr/local/bin/cabextract
    :
  <中略>
    :
  /usr/local/Library/LinkedKegs/wget
  /usr/local/Library/LinkedKegs/wine
  /usr/local/Library/LinkedKegs/winetricks

Warning: Your XQuartz (2.7.4) is outdated
Please install XQuartz 2.7.7:
  https://xquartz.macosforge.org

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
```

`doctor`で確認するといろいろとエラーが（汗

```
$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
```

今度はエラー出なかった、再インストール

```
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 240663, done.
remote: Total 240663 (delta 0), reused 0 (delta 0), pack-reused 240663
Receiving objects: 100% (240663/240663), 33.71 MiB | 544.00 KiB/s, done.
Resolving deltas: 100% (179175/179175), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at 3e7fe5b influxdb 0.9.0-rc19 (devel)
==> Installation successful!
==> Next steps
Run `brew help` to get started
```

`doctor`だとやはり同じエラー言われてるコマンドを打ちますか・・・

```
$ brew prune
Pruned 0 dead formulae
Tapped 155 formulae
Pruned 751 symbolic links and 39 directories from /usr/local
```

```
$ cd /usr/local/Library && git stash && git clean -d -f
No local changes to save
Removing Aliases/firefly
Removing Aliases/hugs
Removing Aliases/jslint
Removing Aliases/p4
Removing Aliases/p4d
Removing Aliases/rbx
Removing Aliases/ree
    :
  <中略>
    :
Removing Homebrew/test/test_raise_plus.rb
Removing Homebrew/vendor/LICENSE
Removing Homebrew/vendor/multi_json.rb
Removing Homebrew/vendor/multi_json/
```

わーなんかいっぱい消されたｗ

```
$ brew update
Updated Homebrew from 3e7fe5b4 to 3e7fe5b4.
==> New Formulae
homebrew/dupes/bzip2					    josegonzalez/php/php53-yp
homebrew/dupes/krb5					    josegonzalez/php/php53-yrmcds
homebrew/dupes/libedit					    josegonzalez/php/php53-zookeeper
homebrew/dupes/xar					    josegonzalez/php/php54-augmentedtypes
josegonzalez/php/behat					    josegonzalez/php/php54-binpack
    :
  <中略>
    :
josegonzalez/php/php53-http		josegonzalez/php/php54-http		josegonzalez/php/wp-cli
josegonzalez/php/php53-igbinary		josegonzalez/php/php54-igbinary
==> Deleted Formulae
homebrew/dupes/ab					    josegonzalez/php/abstract-php
homebrew/dupes/ant					    josegonzalez/php/abstract-php-extension
homebrew/dupes/apr					    josegonzalez/php/php-md
homebrew/dupes/apr-util					    josegonzalez/php/php52
homebrew/dupes/httpd					    josegonzalez/php/php53-intl
homebrew/dupes/perl					    josegonzalez/php/php54-intl
```


```
$ 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: Your XQuartz (2.7.4) is outdated
Please install XQuartz 2.7.7:
  https://xquartz.macosforge.org
```

うーん、まだ警告でている。
バージョンあげろって事ですね。`brew udpate`で上がらないのね・・

サイトにいって`XQuartz-2.7.7.dmg`をダウンロード`dmg`を開くとこんどは`pkg`それも開いてインストール

`brew doctor`やっぱりさっきと同じようにあげろとでる。
`ターミナル`を再起動

```
$ brew doctor
Your system is ready to brew.
```

いつの間にか壊れてるとか、壊れている自身で`cleanup`コマンドとかやめてほしいな。