我刚刚从优胜美地升级到El Capitan(并复制了从El Capitan升级到Sierra的问题),当我尝试在终端内键入例如git状态时,我得到以下错误:

xcrun: error: invalid active developer path
 (/Library/Developer/CommandLineTools), missing xcrun at:
 /Library/Developer/CommandLineTools/usr/bin/xcrun

我没有安装Xcode,从来没有。 有人有办法吗?


当前回答

找到解决问题的方法了。

xcode-select --install

这将提示安装必要的命令行工具。

其他回答

我尝试了xcode-select -install解决方案,但它没有帮助我,我从Sierra更新到High,发生了这样的情况,我的解决方案:

sudo xcode-select --reset

我刚升级到High Sierra,我不能运行xcode-select -install。首先,我必须从应用商店安装xcode。然后我运行xcode-select——install。然后我必须运行sudo xcodebuild -license,同意条款,然后我终于可以再次运行git命令。

对于那些在升级后也有heroku命令行工具问题的人,我还必须在我的终端中做以下工作:

xcode-select --install 
brew install heroku/brew/heroku
brew link --overwrite heroku

看来升级到High Sierra除了迫使我重新安装xcode工具外,还扰乱了我的符号链接。我一直得到'不是一个目录'错误:

▸ stat /Users/mattymc/.local/share/heroku/client/bin/heroku: not a directory  
▸ fork/exec /Users/mattmcinnis/.local/share/heroku/client/bin/heroku: not a directory 

希望能帮你省一个小时:)

对我来说,在我删除了Xcode之后,我必须切换活动开发人员路径,如下所示: Sudo xcode-select -s /

在macOS 10.14中,如果安装了两个或多个版本,也可能出现此问题。如果你喜欢xCode GUI,你可以通过进入首选项- CMD +,选择位置选项卡并选择命令行工具的版本来实现。请参考附件的打印画面。