macOS をアップデートしたあと Command Line Tools のインストールが失敗する

ちょっとハマったので備忘録。brew install でパッケージをインストールしようとしたらこんなエラーが出力された。

Error: The following formula cannot be installed from bottle and must be built from source.
Install the Command Line Tools:
  xcode-select --install

先日、macOS をアップデートした影響で Command Line Tools がなくなったっぽい。言われた通り、xcode-select --install を実行。

$ xcode-select --install

インストーラーが起動してそこそこ時間がかかった挙げ句、「ソフトウェアをインストールできません」と表示される。代わりに Apple Developers から dmg をダウンロードして実行してみたが同様。(こっちもそこそこ時間がかかる...)

解決策

OS アップデート前の Command Line Tools の旧ディレクトリが残っているとインストールが失敗するっぽい。(/Library/Developer/CommandLineTools)

$ sudo rm -rf /Library/Developer/CommandLineTools # 消すのが心配ならリネームでもOK
$ sudo xcode-select --install

現場からは以上です。