Homebrewのパーミッションが壊れたとき


久しぶりにHomebrewを使って新しいツールを導入しようとしたら、

```
pcname:~ username$ brew --version
0.9.5
pcname:~ username$ 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
```

などとなった

`Permission denied`は嫌いです。

`unable to unlink CONTRIBUTING.md: Permission denied` で調べたところ。

* パーミッションを修正すること
* 手動でFormulaを更新すること

以下のようにコマンド実行して解決した。

```
$ cd $(brew --prefix)
$ sudo chown -R [username]:admin $(brew --prefix)
$ git fetch --all
$ git reset --hard origin/master
```

```コマンド履歴
pcname:~ username$ cd $(brew --prefix)
pcname:local username$ pwd
/usr/local
pcname:local username$ ls -af
.				Library
..				LICENSE.txt
.git				mysql
.gitignore			mysql-5.6.14-osx10.7-x86_64
.yardopts			opt
bin				packager
Cellar				php5
CODEOFCONDUCT.md		php5-5.3.28-20140112-174528
CONTRIBUTING.md			README.md
etc				sbin
include				share
lib				SUPPORTERS.md
pcname:local username$ sudo chown -R pcname:admin $(brew --prefix)
Password:
chown: pcname: illegal user name
pcname:local username$ sudo chown -R username:admin $(brew --prefix)
pcname:local username$ git fetch --all
Fetching origin
pcname:local username$ git reset --hard origin/master
Checking out files: 100% (3985/3985), done.
HEAD is now at fbcd95b download_strategy: correct S3 url regex
pcname:local username$ pwd
/usr/local
pcname:local username$ cd
pcname:~ username$ brew update
To restore the stashed changes to /usr/local run:
  'cd /usr/local && git stash pop'
Updated 2 taps (homebrew/dupes, homebrew/versions).
==> New Formulae
homebrew/dupes/bc
homebrew/dupes/srm
homebrew/versions/android-ndk-r10d
homebrew/versions/ansible18
homebrew/versions/ansible19
homebrew/versions/antlr3
homebrew/versions/apache-spark141
homebrew/versions/apache-spark15
homebrew/versions/astyle204
homebrew/versions/boot2docker162
homebrew/versions/cassandra21
homebrew/versions/cassandra22
homebrew/versions/docker162
homebrew/versions/docker171
homebrew/versions/elasticsearch17
homebrew/versions/elasticsearch21
homebrew/versions/erlang-r17
homebrew/versions/freetds091
homebrew/versions/gcc6
homebrew/versions/gegl02
homebrew/versions/go14
homebrew/versions/go15
homebrew/versions/gradle24
homebrew/versions/gradle26
homebrew/versions/gradle27
homebrew/versions/gradle28
homebrew/versions/influxdb08
homebrew/versions/iojs
homebrew/versions/jruby168
homebrew/versions/jruby1721
homebrew/versions/jruby9000
homebrew/versions/jython253
homebrew/versions/kettle54
homebrew/versions/kibana41
homebrew/versions/kibana43
homebrew/versions/libidn2
homebrew/versions/libxc21
homebrew/versions/libxml278
homebrew/versions/llvm37
homebrew/versions/logstash21
homebrew/versions/lz4r117
homebrew/versions/mapnik2
homebrew/versions/mariadb100
homebrew/versions/mysql56
homebrew/versions/nasm21106
homebrew/versions/nifi021
homebrew/versions/node012
homebrew/versions/node4-lts
homebrew/versions/postgresql94
homebrew/versions/protobuf260
homebrew/versions/ruby22
homebrew/versions/saxon6
homebrew/versions/selenium-server-standalone245
homebrew/versions/subversion18
homebrew/versions/zeromq405
==> Updated Formulae
homebrew/dupes/diffstat                  homebrew/versions/jetty76              
homebrew/dupes/ed                        homebrew/versions/libmongoclient-legacy
homebrew/dupes/file-formula              homebrew/versions/libpng12             
homebrew/dupes/grep                      homebrew/versions/llvm36               
homebrew/dupes/krb5                      homebrew/versions/lua53                
homebrew/dupes/lapack                    homebrew/versions/mongodb26            
homebrew/dupes/less                      homebrew/versions/mysql55              
homebrew/dupes/libedit                   homebrew/versions/nettle3              
homebrew/dupes/libpcap                   homebrew/versions/node010              
homebrew/dupes/nano                      homebrew/versions/node08               
homebrew/dupes/ncurses                   homebrew/versions/openssl101           
homebrew/dupes/openldap                  homebrew/versions/play13               
homebrew/dupes/openssh                   homebrew/versions/postgresql8          
homebrew/dupes/rsync                     homebrew/versions/postgresql9          
homebrew/dupes/screen                    homebrew/versions/postgresql91         
homebrew/dupes/tcpdump                   homebrew/versions/postgresql92         
homebrew/dupes/whois                     homebrew/versions/postgresql93         
homebrew/versions/bind99                 homebrew/versions/redis26              
homebrew/versions/gcc48                  homebrew/versions/redis28              
homebrew/versions/gcc49                  homebrew/versions/ruby187              
homebrew/versions/gcc5                   homebrew/versions/ruby193              
homebrew/versions/giflib5                homebrew/versions/ruby20               
homebrew/versions/glfw3                  homebrew/versions/ruby21               
homebrew/versions/gnupg21                homebrew/versions/tomcat6              
homebrew/versions/gnutls34               homebrew/versions/tomcat7              
homebrew/versions/hdf4                   homebrew/versions/v8-315               
homebrew/versions/jenkins-lts          
==> Deleted Formulae
homebrew/dupes/fetchmail                 homebrew/versions/elasticsearch13      
homebrew/dupes/gdb                       homebrew/versions/elasticsearch14      
homebrew/versions/allegro5               homebrew/versions/mapnik071            
homebrew/versions/apache-spark121        homebrew/versions/openssl098           
homebrew/versions/elasticsearch-0.20     homebrew/versions/pandoc-citeproc05    
homebrew/versions/elasticsearch090       homebrew/versions/pandoc1131           
homebrew/versions/elasticsearch11        homebrew/versions/squid2               
homebrew/versions/elasticsearch12      
pcname:~ username$ 
pcname:~ username$ brew --version
Homebrew 0.9.5 (git revision fbcd9; last commit 2016-03-06)
```

すっきり。