今天把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