Warning: Broken symlinks were found. Remove them with



# 事象 : Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins
- 環境
    - macOS Monterey version12.2.1
    - Homebrew 3.3.15

```zsh
# お医者さんに掃除を勧められたので
$ 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 or file an issue; just ignore this. Thanks!

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/lib/docker/cli-plugins
  /usr/local/share/fish/vendor_completions.d/docker-compose.fish
  /usr/local/share/fish/vendor_completions.d/docker.fish
  /usr/local/share/zsh/site-functions/_docker
  /usr/local/share/zsh/site-functions/_docker_compose

# 掃除したらなんか言われた
$ brew cleanup
Warning: Skipping c-ares: most recent version 1.18.1_1 not installed
Warning: Skipping ca-certificates: most recent version 2022-02-01 not installed
Warning: Skipping freetype: most recent version 2.11.1 not installed
Warning: Skipping gdbm: most recent version 1.23 not installed
Warning: Skipping git: most recent version 2.35.1 not installed
Warning: Skipping libuv: most recent version 1.43.0 not installed
Warning: Skipping node: most recent version 17.5.0 not installed
Warning: Skipping openjdk: most recent version 17.0.2 not installed
Warning: Skipping openssl@1.1: most recent version 1.1.1m not installed
Warning: Skipping pcre2: most recent version 10.39 not installed
Warning: Skipping python@3.9: most recent version 3.9.10 not installed
Warning: Skipping sqlite: most recent version 3.37.2 not installed
Warning: Skipping tomcat: most recent version 10.0.16 not installed
Warning: Skipping tomcat@8: most recent version 8.5.75 not installed
Warning: Skipping tomcat@9: most recent version 9.0.58 not installed
Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins
```

## 原因 : 掃除したい場所に権限がないから
```zsh
# 「Permission denied」ということは権限がないのかと思ったら・・・ないね
$ ls -la /usr/local/lib/ | grep docker
drwxr-xr-x   3 root       admin    96 10 28 22:24 docker
```

### 対応 : ディレクトリの持ち主を変更してから掃除する
```zsh
# 再起的(-R)に持ち主を自分に変更する
$ sudo chown -R ponsuke /usr/local/lib/docker
Password:

$ ls -la /usr/local/lib/ | grep docker    
drwxr-xr-x   3 ponsuke  admin    96 10 29 20:03 docker

# 今一度、掃除する
$ brew cleanup
Warning: Skipping c-ares: most recent version 1.18.1_1 not installed
Warning: Skipping ca-certificates: most recent version 2022-02-01 not installed
Warning: Skipping freetype: most recent version 2.11.1 not installed
Warning: Skipping gdbm: most recent version 1.23 not installed
Warning: Skipping git: most recent version 2.35.1 not installed
Warning: Skipping libuv: most recent version 1.43.0 not installed
Warning: Skipping node: most recent version 17.5.0 not installed
Warning: Skipping openjdk: most recent version 17.0.2 not installed
Warning: Skipping openssl@1.1: most recent version 1.1.1m not installed
Warning: Skipping pcre2: most recent version 10.39 not installed
Warning: Skipping python@3.9: most recent version 3.9.10 not installed
Warning: Skipping sqlite: most recent version 3.37.2 not installed
Warning: Skipping tomcat: most recent version 10.0.16 not installed
Warning: Skipping tomcat@8: most recent version 8.5.75 not installed
Warning: Skipping tomcat@9: most recent version 9.0.58 not installed
Pruned 5 symbolic links and 1 directories from /usr/local

# 元気になった
$ brew doctor
Your system is ready to brew.
```












# 事象 : Warning: Broken symlinks were found. Remove them with `brew cleanup`
- 環境
    - macOS Big Surバージョン11.1
    - homebrew-core (git revision 6a9a9; last commit 2021-01-28)
    - homebrew-cask (git revision 125cd; last commit 2021-01-28)

```bash
$ 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 or file an issue; just ignore this. Thanks!

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/share/zsh/site-functions/_brew_cask
```

## 原因 : 不明
そういえば、最近Caskがなんか変わったなぁ・・・・
[Homebrew Caskインストールしなくて良くなったり](https://qiita.com/ponsuke0531/items/73f540391aa3827130d8)・・・
[Caskの使い方が変わったり](https://qiita.com/ponsuke0531/items/c701596ecd79ba08fbaf)・・・

### 対応 : 古いシンボリックリンクもキャッシュも削除する
参考 : [Mac OSのbrewコマンドを使う人は&#12289;たまにお掃除をしましょう - manavi2020](https://manavi2020.blogspot.com/2020/04/mac-osbrew.html)

```bash
# どばっと掃除する
$ brew cleanup
Warning: Skipping git: most recent version 2.30.0 not installed
Warning: Skipping openjdk@11: most recent version 11.0.9 not installed
Removing: /Users/ponsuke/Library/Caches/Homebrew/openjdk@11--11.0.8.catalina.bottle.tar.gz... (180.7MB)
Warning: Skipping openjdk@8: most recent version 1.8.0+282 not installed
Removing: /Users/ponsuke/Library/Caches/Homebrew/openjdk@8--1.8.0+275.big_sur.bottle.tar.gz... (98.3MB)
Warning: Skipping pcre2: most recent version 10.36 not installed
Removing: /Users/ponsuke/Library/Caches/Homebrew/pcre2--10.35.catalina.bottle.tar.gz... (2.0MB)
Removing: /Users/ponsuke/Library/Caches/Homebrew/Cask/font-ricty-diminished--4.1.1.tar.gz... (8.1MB)
Removing: /Users/ponsuke/Library/Logs/Homebrew/libpng... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/freetype... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/openjdk@11... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/payara... (102B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/gettext... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/pcre2... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/openjdk@8... (64B)
Removing: /Users/ponsuke/Library/Logs/Homebrew/git... (64B)
Pruned 1 symbolic links and 22 directories from /usr/local

# すっきり！
$ brew doctor
Your system is ready to brew.
```

# 事象 : Warning: Broken symlinks were found. Remove them with `brew prune`
```bash
$ 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 or file an issue; just ignore this. Thanks!

Warning: Broken symlinks were found. Remove them with `brew prune`:
  /usr/local/opt/httpd24
```

## 原因 : アンイストールしたから
そういえばApacheをアンイストールしていた。

```bash
# やはりない
$ brew list | grep httpd
$ 
```

### 対応 : 壊れたシンボリックリンクを消す
```bash
$ brew prune
Pruned 1 symbolic links and 11 directories from /usr/local
# 治った
$ brew doctor
Your system is ready to brew.
```