[macOS General] brew install や brew cleanup 実行時のパーミッションエラーを解決する

該当ディレクトリの権限をチェックします。

`brew cleanup` で下記のようなパーミッションエラーが表示されました。

“`prettyprinted
% brew cleanup
Removing: /usr/local/Cellar/php/7.3.1… (191 files, 17.5MB)
Error: Could not remove /usr/local/Cellar/php/7.3.1! Check its permissions.
Removing: /usr/local/Cellar/php/7.3.3… (191 files, 17.6MB)
Error: Could not remove /usr/local/Cellar/php/7.3.3! Check its permissions.
Pruned 0 symbolic links and 8 directories from /usr/local
“`

`brew doctor` は正常です。

“`prettyprinted
% brew doctor
Your system is ready to brew.
“`

該当ディレクトリがどのような権限になっているのか確認します。
このケースの場合は `/usr/local/Cellar/php*` が対象です。

“`prettyprinted
% ls -al /usr/local/Cellar/php*
lrwxr-xr-x 1 foobar admin 3 3 6 2018 php72@ -> php

php:
total 0
drwxr-xr-x 5 foobar staff 160 5 24 19:57 ./
drwxr-xr-x 172 foobar admin 5504 1 29 17:37 ../
drwxr-xr-x 10 foobar staff 320 3 28 18:26 7.3.1/
drwxr-xr-x 10 foobar staff 320 5 24 20:00 7.3.3/
drwxr-xr-x 15 foobar staff 480 5 24 20:00 7.3.5/

phpunit:
total 0
drwxr-xr-x 3 foobar admin 96 5 24 20:02 ./
drwxr-xr-x 172 foobar admin 5504 1 29 17:37 ../
drwxr-xr-x 5 foobar admin 160 5 24 20:02 8.1.5/
“`

`staff` 権限になっていましたので `admin` に変更します。

> * [macos – How to fix homebrew permissions? – Stack Overflow](https://stackoverflow.com/questions/16432071/how-to-fix-homebrew-permissions)

“`prettyprinted
% sudo chown -R “$USER”:admin /usr/local/Cellar/php*
“`

これで問題なく削除が出来るようになりました。

“`prettyprinted
% brew cleanup
Removing: /usr/local/Cellar/php/7.3.1… (192 files, 17.5MB)
Removing: /usr/local/Cellar/php/7.3.3… (192 files, 17.6MB)
“`