【随時更新】brew doctorでWarning: xxxxxxx.と表示された時の処方箋

MacのパッケージマネージャーHomebrewには現在の状態を表示する`doctor`コマンドが有ります。通常は以下の様に`Your system is ready to brew.`と出力されるのが理想です。

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

ところが、使っていると様々な要因で健康診断に引っ掛かる様になります。

# 症例1: Warning: You have unlinked kegs in your Cellar.
Homebrewが管理しているアプリケーションのシンボリックリンクが壊れた場合にこの症状が出ます。

```bash
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  r
  gcc@8

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
  /usr/local/bin/c++-8
  /usr/local/bin/cpp-8
  /usr/local/bin/g++
  /usr/local/bin/g++-8
  /usr/local/bin/gcc
  /usr/local/bin/gcc-8
  /usr/local/bin/gcc-ar-8
  /usr/local/bin/gcc-nm-8
  /usr/local/bin/gcc-ranlib-8
  /usr/local/bin/gcov-8
  /usr/local/bin/gcov-dump-8
  /usr/local/bin/gcov-tool-8
  /usr/local/bin/gfortran-8
  /usr/local/bin/x86_64-apple-darwin20-c++-8
  /usr/local/bin/x86_64-apple-darwin20-g++-8
  /usr/local/bin/x86_64-apple-darwin20-gcc-8
  /usr/local/bin/x86_64-apple-darwin20-gcc-8.4.0
  /usr/local/bin/x86_64-apple-darwin20-gcc-ar-8
  /usr/local/bin/x86_64-apple-darwin20-gcc-nm-8
  /usr/local/bin/x86_64-apple-darwin20-gcc-ranlib-8
  /usr/local/bin/x86_64-apple-darwin20-gfortran-8
  /usr/local/include/c++/8.4.0
  /usr/local/lib/gcc/8
  /usr/local/share/gcc-8.4.0
  /usr/local/share/man/man1/cpp-8.1
  /usr/local/share/man/man1/g++-8.1
  /usr/local/share/man/man1/gcc-8.1
  /usr/local/share/man/man1/gcov-8.1
  /usr/local/share/man/man1/gcov-dump-8.1
  /usr/local/share/man/man1/gcov-tool-8.1
  /usr/local/share/man/man1/gfortran-8.1
  /usr/local/share/man/man7/fsf-funding-8.7
  /usr/local/share/man/man7/gfdl-8.7
  /usr/local/share/man/man7/gpl-8.7
```

## 処方箋
`brew link`コマンドで修復します。

```bash
brew link r gcc@8
```

# 症例2: Warning: Some installed formulae are deprecated or disabled.
この症例は1つのアプリケーションに対して複数のバージョンがインストールされている状態で出る場合が有る様です。筆者の環境ではlua@5.1とlua@5.4がインストールされており、競合状態となっていたため、警告が出ました。

```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: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  lua@5.1
```

## 処方箋
警告で表示されているバージョンをアンインストールすると直りました。

```bash
brew uninstall lua@5.1
```

# 症例3: Warning: Broken symlinks were found.
何らかの原因でシンボリックリンクが壊れた状態になっている場合に発生する様です。

```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`:
  /opt/homebrew/etc/bash_completion.d/docker-compose
```

確かにリンク切れになっています。

```bash
$ ls /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
ls: /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion: No such file or directory
```

## 処方箋
メッセージで表示されている様に`brew cleanup`を実行します。

```bash
brew cleanup
```

# 症例4: Warning: You have uncommitted modifications to Homebrew/brew.
何らかの変更がHomebrew管理下のアプリケーションに加わった時に発生するようです。

```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: You have uncommitted modifications to Homebrew/brew.
If this is 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 /opt/homebrew && git stash -u && git clean -d -f

Uncommitted files:
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/activesupport-6.1.7.2/MIT-LICENSE
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/addressable-2.8.1/LICENSE.txt
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/connection_pool-2.3.0/LICENSE
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/domain_name-0.5.20190701/LICENSE.txt
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/http-cookie-1.0.5/LICENSE.txt
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/i18n-1.12.0/MIT-LICENSE
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/mechanize-2.8.5/LICENSE.txt
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.13.10-arm64-darwin/LICENSE-DEPENDENCIES.md
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/nokogiri-1.13.10-arm64-darwin/LICENSE.md
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/public_suffix-5.0.1/LICENSE.txt
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/ruby-macho-3.0.0/LICENSE
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.3/LICENSE
  ?? Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/webrick-1.8.1/LICENSE.txt
```

## 処方箋
メッセージに表示されている様に`cd /opt/homebrew && git stash -u && git clean -d -f`を実行します。

```bash
$ cd /opt/homebrew && git stash -u && git clean -d -f
Saved working directory and index state WIP on stable: e57a87cfe Merge pull request #16085 from samford/improve-date-version-parsing-take-2
```

処方箋実行後、`brew doctor`を再度実行します。

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

# 症例5: Warning: Some installed kegs have no formulae!
どこかのタイミングでHomebrewのインストール済アプリのデータベースの整合性が崩れてしまったことが原因の様です。

```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: Some installed kegs have no formulae!
This means they were either deleted or installed manually.
You should find replacements for the following formulae:
  python-platformdirs
  python-distlib
  python-filelock
```

## 処方箋
`brew uninsall --ignore-dependencies xxxxx`を実行します。

```bash
$ brew uninstall --ignore-dependencies python-platformdirs python-distlib python-filelock
Uninstalling /opt/homebrew/Cellar/python-platformdirs/4.2.0... (36 files, 172.2KB)
Uninstalling /opt/homebrew/Cellar/python-distlib/0.3.8... (59 files, 2.3MB)
Uninstalling /opt/homebrew/Cellar/python-filelock/3.13.1... (36 files, 60.3KB)
```

因みに、`--ignore-dependencies`オプションを着けない場合は、以下の様にエラーとなります。

```bash
$ brew uninstall python-platformdirs python-distlib python-filelock
Error: Refusing to uninstall /opt/homebrew/Cellar/python-distlib/0.3.8, /opt/homebrew/Cellar/python-filelock/3.13.1 and /opt/homebrew/Cellar/python-platformdirs/4.2.0
because they are required by pipenv and virtualenv, which are currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python-platformdirs python-distlib python-filelock
```

# Warning: /usr/bin occurs before /opt/homebrew/bin in your PATH.

```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: /usr/bin occurs before /opt/homebrew/bin in your PATH.
This means that system-provided programs will be used instead of those
provided by Homebrew. Consider setting your PATH so that
/opt/homebrew/bin occurs before /usr/bin. Here is a one-liner:
  echo 'export PATH="/opt/homebrew/bin:$PATH"' >> /Users/yuhkiyano/.bash_profile

The following tools exist at both paths:
  bashbug
  corelist
  cpan
  enc2xs
  encguess
  ex
  git
  git-receive-pack
  git-shell
  git-upload-archive
  git-upload-pack
  h2ph
  h2xs
  instmodsh
  json_pp
  libnetcfg
  openssl
  perl
  perlbug
  perldoc
  perlivp
  perlthanks
  piconv
  pip3
  pl2pm
  pod2html
  pod2man
  pod2text
  pod2usage
  podchecker
  prove
  ptar
  ptardiff
  ptargrep
  python3
  rview
  rvim
  shasum
  splain
  streamzip
  tclsh
  vi
  view
  vim
  vimdiff
  vimtutor
  wish
  xsubpp
  xxd
  zipdetails
  ```

  ## 処方箋
  この警告が出る時は、環境変数`PATH`内で`/usr/bin`よりも先に`/opt/homebrew/bin`が宣言されてしまっているので、PATHの宣言の順番等を確認して正しい順番になっているかまずは確認します。警告メッセージに対処方法が記載されていますが、あくまで対処療法でしかなく、根本解決にはなりません。

# Warning: You have the following deprecated, official taps tapped:

```bash
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: You have the following deprecated, official taps tapped:
  Homebrew/homebrew-aliases
Untap them with `brew untap`.
```

## 処方箋
非推奨となったリポジトリと関連付いている場合に出る警告のようです。警告メッセージに出ているコマンドを用いて`untap`します。

```bash
$ brew untap Homebrew/homebrew-aliases
Untapping homebrew/aliases...
Untapped (44 files, 262.6KB).
```

### 参考
上記のHomebrew/homebrew-aliasesは2025年2月8日に開発が終了した様です。

https://github.com/Homebrew/homebrew-aliases/blob/master/README.md?plain=1

### 参考

https://qiita.com/sammrai/items/85ed5e914d424fbf9fd6

# Warning: The following formulae have the same name as core formulae:
この警告はHomebrewのCore部分で利用されているformulaと同名のformulaが存在した場合に出力されます。

```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: The following formulae have the same name as core formulae:
  hashicorp/tap/consul
  hashicorp/tap/consul-template
  hashicorp/tap/envconsul
  hashicorp/tap/levant
  hashicorp/tap/nomad
  hashicorp/tap/packer
  hashicorp/tap/terraform
  hashicorp/tap/terraform-ls
  hashicorp/tap/vault
  hashicorp/tap/waypoint
  xcodesorg/made/xcodes
Their taps are in use, so you must use these full names throughout Homebrew.
```
## 処方箋
以下の様に対処しました。

```bash: 一段階目
brew uninstall --formula xcodesorg/made/xcodes
brew untap xcodesorg/made
brew uninstall packer
brew untap hashicorp/tap
```

untapを実行する場合は、依存関係をアンインストールする必要が有ります。アンインストールを実行せずにuntapを実行すると以下のエラーメッセージが出力されます。

```bash
$ brew untap hashicorp/tap
Error: Refusing to untap hashicorp/tap because it contains the following installed formulae or casks:
packer
```

### 参考
この警告の解決方法は全く情報が無かったので、HomebrewのコミュニティのDiscussionで質問をして開発者の方から対処方法を教えて貰いました。

https://github.com/orgs/Homebrew/discussions/5989

# Reference

https://qiita.com/Ytz_Ichi/items/94e1c5c45fc8fd4459fa