覚えたら書く

IT関係のデベロッパとして日々覚えたことを書き残したいです。twitter: @yyoshikaw

macOS - gccでエラーが出た時の対処

MacBookでひさしびりに gcc 使おうとしたら invalid active developer path というエラーが出ました。

yukiMacBook-Pro:~ yuki$ gcc -v
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
yoshikawayuukinoMacBook-Pro:~ yuki$ xcode-select --install
xcode-select: note: install requested for command line developer tools


こうなった場合 ターミナルから以下を実行します

xcode-select --install

実際に実行すると

yukiMacBook-Pro:~ yuki$ xcode-select --install
xcode-select: note: install requested for command line developer tools

インストールするかどうかのダイアログが表示されます。「インストール」をクリックします。

f:id:nini_y:20200321132426p:plain


使用許諾契約のダイアログが表示されます。「同意する」をクリックします。

f:id:nini_y:20200321132452p:plain


最終的にインストール完了のダイアログが表示されます。「完了」をクリックします。

f:id:nini_y:20200321132907p:plain


これで gcc が使えるように復旧しました。(以下は gcc -v で動作確認しています)

yukiMacBook-Pro:~ yuki$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin