我更新了最新的操作系统,和/或重新启动了我的计算机(每次重大更新都会发生这种情况,但这次我所做的只是在2022-09-13年重新启动我的计算机)

今天早上,我在MacBook pro的命令行中导航到我的工作代码库,在存储库中键入“gitstatus”,收到一个错误:

(2022年9月,这个错误大不相同,但我没有捕捉到它)

xcrun:错误:无效的活动开发人员路径(/Library/developer/CommandLineTools),在以下位置缺少xcrun:/Librari/developer/CommandLineTools/usr/bin/xcrun

git不起作用!

如何修复git和命令行工具?


当前回答

除了dustbuster的答案,我还需要使用以下命令设置Xcode文件夹的路径:

sudo xcode-select -switch /Library/Developer/CommandLineTools

其他回答

我已经在以前的主要版本中使用了公认答案中给出的xcode select--install。

我刚刚升级到OS X 10.15 Catalina,并在OS升级完成后再次从首选项运行软件更新工具。Xcode实用程序更新在那里可用,它还使用刚刚输出的git对问题进行了排序xcrun:错误:无效的活动开发人员路径(/Library/developer/CommandLineTools)

打开终端:

安装XCode开发人员工具并解决问题。

$ xcode-select --install

如果您有多个版本,请将路径重置为Xcode:

$ xcode-select --switch /Applications/Xcode.app
$ xcode-select --switch /Library/Developer/CommandLineTools

M1的后续工作

ProductName:    macOS
ProductVersion: 11.2.1
BuildVersion:   20D74

% xcode-select --install

同意“条款和条件”提示,成功后将返回以下消息。

% xcode-select: note: install requested for command line developer tools

对于macOS ventura,只需为我重新安装git

如果您手动下载了Xcode(即不是从App Store下载)或根本没有Xcode:

sudo rm-rf/库/开发人员/命令行工具去https://developer.apple.com/download/more/下载Xcode 10的命令行工具(macOS 10.14)设置命令行工具

如果您从App Store安装了Xcode:

xcode select--安装