MacOS系统升级后出现git: error: unable to find utility “git”, not a developer tool or in PATH

今天把Mac系统升级到macOS Big Sur 11.1,升级完后打开终端,输入git status命令,意外出现“git: error: unable to find utility “git”, not a developer tool or in PATH”的提示:

sh: line 1: 3644 Bus error: 10 /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
 -find git 2> /dev/null
git: error: unable to find utility "git", not a developer tool or in PATH

不仅是git,运行gcc等命令也会出现类似的提示:”gcc: error: unable to find utility “gcc”, not a developer tool or in PATH”。

网上有人说是python的版本问题,运行python --version查看,默认还是python 2.7.16,应该没问题才对。后来查看StackOverflow的回答,运行如下两条命令解决了问题:

xcode-select --install
sudo xcode-select -s /Library/Developer/CommandLineTools

如果之前安装过Xcode的命令行工具,执行第一条命令会有下面的提示:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

不用管,接着运行第二条命令就OK了。

参考

1. error: unable to find utility “git”, not a developer tool or in PATH


【AD】DMIT美国洛杉矶Pro VPS套餐,$14.9/月起,1G-10Gbps带宽/CN2 GIA线路/有高防GIA可选
【AD】美国洛杉矶CN2 VPS/香港CN2 VPS/日本CN2 VPS推荐,延迟低、稳定性高、免费备份_搬瓦工vps