https://developer.apple.com/download/more/?=command%20line%20tools
对于那些使用较新版本的Xcode(我正在使用14.3),您需要安装命令行工具。
我建议两种方法。
在终端上运行以下命令:
xcodebuild -runFirstLaunch xcode-select --install
或从this link下载可安装的DMG文件(Xcode 14.3的命令行工具)并进行安装。
当我尝试在macOS 13.3上安装brew时,我遇到了这个问题。
sudo xcode-select --install
--switch
命令。希望这可以帮助你。以上方法都对我无效。我最初是单独安装了命令行工具,然后再安装了整个Xcode。对我有效的方法是按照这里所示的步骤卸载命令行工具。然后,当我再次尝试运行xcode-select
时,系统会要求我重新安装它们。
*顺便说一下,我找到这个帖子的原因是因为我使用macports
安装了一些库(特别是gcc
),可能是使用旧版的命令行工具,然后在开发过程中安装了完整的Xcode。所以,对于我的情况,我必须在删除独立的命令行工具、重新安装它们、重新安装gcc
之后重新安装macports
,然后我的编译才能正常工作。
就我的情况而言,
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
不能工作是因为我的Xcode有一些特殊的名称。例如)Xcode_11.2.0_beta_2_stackoverflow.app
cd /applications
ls
然后我找到了我的Xcode名称,然后用它替换掉
sudo xcode-select -s /Applications/{myXcodeName}.app/Contents/Developer
这对我有用。
以上解决方案都没能帮助我。我正在处理一个旧项目,并且我在计算机上全局安装了最新版本的NodeJs(v14.x)。
对我来说,任何高于10.1.x的node版本都无法工作,当我测试时收到了与上述相同的错误。
npm install
现在可以运行。现在我需要更新我的版本,或者在我的package.json文件中指定我的node版本。
sudo xcode-select -s /Applications/Xcode 10.app/Contents/Developer
languoguangs-iMac:/ languoguang$ sudo xcode-select -s /Applications/Xcode 10.app/Contents/Developer
xcode-select: error: invalid argument '10.app/Contents/Developer'
Usage: xcode-select [options]
Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).
Options:
-h, --help print this help message and exit
-p, --print-path print the path of the active developer directory
-s <path>, --switch <path> set the path for the active developer directory
--install open a dialog for installation of the command line developer tools
-v, --version print the xcode-select version
-r, --reset reset to the default command line tools path
languoguangs-iMac:/ languoguang$ sudo xcode-select -s "/Applications/Xcode 10.app/Contents/Developer"
因为我的应用程序中的Xcode名称是“Xcode 10”,
sudo xcode-select -s "/Applications/Xcode 10.app/Contents/Developer"
运作正常。