在运行需要 node-gyp
的 npm install
时看到以下错误...但可能由需要 xcode-select
的任何东西触发。
xcode-select:错误:工具“xcodebuild”需要 Xcode,但活动开发者目录“/Library/Developer/CommandLineTools”是命令行工具实例
问题是什么?
当需要完整的常规 Xcode 时 xcode-select
开发者目录指向 /Library/Developer/CommandLineTools
时会发生此问题(在 Xcode 之后安装 CommandLineTools 时发生)
解决方案:
如果您还没有,请安装 Xcode(从 https://appstore.com/mac/apple/xcode 获取)。接受条款和条件。确保 Xcode 应用程序位于 /Applications 目录中(不是 /Users/{user}/Applications)。使用以下命令将 xcode-select 指向 Xcode 应用开发者目录:sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
注意:确保您的 Xcode 应用程序路径正确。
Xcode:/Applications/Xcode.app/Contents/Developer
Xcode-beta:/Applications/Xcode-beta.app/Contents/Developer
不想安装 Xcode 的其他解决方案:
安装命令行工具(如果您还没有):xcode-select --install 更改活动目录:sudo xcode-select -switch /Library/Developer/CommandLineTools
这对我有用(git)。
xcode-select
:cl.ly/image/2T0u2f2D471a/content
xcodebuild
来安装整个 Xcode 的唯一方法是什么? :-(
尝试使用 npm 安装软件包时遇到问题。我收到错误:“sudo xcode-select -s /Applications//Xcode.app/Contents/Developer/”
要解决这个问题
我打开了 Xcode。
喜好
地点
选择命令行工具:Xcode 6.1.1
现在,当使用 npm 安装软件包时,我不再遇到错误。
Xcode > 首选项 > 位置 > 命令行工具
https://i.stack.imgur.com/QUMTf.png
选择与您的 Xcode 版本匹配的选项。
xcode-select
时一直说“错误:无效的开发者目录”!
只需运行 sudo xcode-select -r
,它应该会自动重置路径。
-r, --reset
Unsets any user-specified developer directory, so that the developer directory will be found via the default search mechanism. This command must be
run with superuser permissions (see sudo(8)), and will affect all users on the system.
在你的终端输入这个
xcode-select --install
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept
以防万一您使用的是 xcode beta:
sudo xcode-select -s /Applications/Xcode-Beta.app/Contents/Developer
我必须先运行这个
sudo xcode-select --reset
然后
sudo xcode-select -switch /Library/Developer/CommandLineTools
然后它起作用了。
--reset
即可解决问题
从 App Store 下载 Xcode。转到 Xcode 首选项/位置/命令行工具您只需将其设置为 Xcode 版本。它自动指向'/Application/Xcode.app'
我在高山脉也遇到了同样的问题。运行以下命令解决了它
npm explore npm -g -- npm install node-gyp@latest
npm -g install node-gyp@latest
重新安装
请按照以下步骤操作:
最新版本的 Xcode 可以从 https://developer.apple.com/xcode/download/ 下载,除非另有说明,否则它将在“下载”中下载。请确保检查您下载和提取 Xcode 的路径 现在与其他下载的应用程序不同,在提取时,Xcode 不提供将其移动到应用程序的选项 注意 XCODE-ACTUAL-LOCATION 或将其移动到应用程序注意如果你已经下载了 Xcode 或 Xcode-beta
根据 4 和 5,执行其中一个命令(未阅读上述说明,请勿全部执行):
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
sudo xcode-select -s /[XCODE-ACTUAL-LOCATION]/Xcode.app/Contents/Developer
sudo xcode-select -s /[XCODE-ACTUAL-LOCATION]/Xcode-beta.app/Contents/Developer
从 App Store 安装 Xcode。安装后使用 root 权限运行 xcodebuild 即 sudo xcodebuild
并接受该语言。在这 npm install bcrypt
工作之后就像一个魅力!
没有 Xcode:创建包含内容的文件 /usr/local/bin/xcodebuild
以欺骗 XcodeSelect
#!/bin/bash
exit 0
chmod +x /usr/local/bin/xcodebuild
xcodebuild
时我遇到了 node-gyp 问题。我宁愿不安装 Xcode 只是为了安装一些与 Mac 和 iOS 开发无关的本机扩展,所以我非常愿意尝试这种技术来基本上只是关闭错误。你知道这样做有什么后果吗?我只能想象 node-gyp 调用 xcodebuild
是有原因的,并且通过执行 exit 0
我们正在破坏给定构建的工具链,但我不确定,因为我不知道为什么会首先使用 xcodebuild
。有任何想法吗?
如果您使用的是 Xcode beta,请运行
sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer
代替
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
我能够在不安装完整的 Xcode 应用程序的情况下解决此错误。但是,您必须安装 xcode 命令行工具。
从 here:
$ cd /usr/bin $ sudo mv xcodebuild xcodebuild.orig(备份以防万一) $ vim xcodebuild 粘贴以下内容:
#!/bin/bash
if [[ $1 == '-version' ]]; then
echo "Xcode 10.2.1"
echo "Build version 10E1001"
else
/usr/bin/xcodebuild.bak $@
fi
$ sudo chmod +x xcodebuild
XCode2: sudo xcode-select -s /Applications/Xcode\ 2.app/Contents/Developer
注意“\”转义空格
我安装了两个 Xcode 实例 xcode.app 和 xcode-beta.app 当我尝试使用 netbeans 创建构建时,它向我显示错误“未找到 netbeans 支持的 xcode 和命令行工具版本”
我按照以下步骤操作:
"xcode-select --print-path" 等于 "/Applications/Xcode.app/Contents/Developer" "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform" 存在 "xcodebuild -version" 启动用“Xcode”
1 之后我发现它指向 xcode-beta.app
所以这是一个很有魅力的解决方案:
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
就上下文而言,今天是 2019 年 1 月 28 日。
在我的 Mac 上,我做了两件事来解决这个问题:
在您的终端中运行以下命令: sudo xcode-select --install 重新启动您的 Mac。
在我重新启动计算机之前,问题一直在我的 Android Studio 中出现。重新启动后,它工作得很好。另请注意,我没有像其他人那样执行任何 --switch
命令。我希望这有帮助。
简单重新安装 xcode-select
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
手动安装命令行工具对我有用。
我通过 App Store 停止了 xcode 仍然无法下载 Homebrew 我通过链接手动安装了命令行工具。 Bing Bang Boom
https://developer.apple.com/download/more/?=command%20line%20tools
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"
因为我在 Application 中的 Xcode 名称是“Xcode 10”,
sudo xcode-select -s "/Applications/Xcode 10.app/Contents/Developer"
作品。
就我而言,
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
它对我有用。
以上都不适合我。我最初是单独安装命令行工具,然后是所有 Xcode。对我有用的是卸载命令行工具,如图 here。然后,当再次尝试运行 xcode-select
时,我被要求重新安装它们。
*顺便说一句,我发现这个线程的原因是因为我用 macports
安装了一些库(特别是 gcc
),大概是使用旧的命令行工具,然后我在开发过程中安装了完整的 Xcode。所以无论如何,就我而言,我必须在删除独立的命令行工具、重新安装它们、重新安装 gcc
之后重新安装 macports
,然后我的编译才起作用。
只需要两个步骤,完全不需要完整的 XCode.app:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
此时弹出“安装软件”对话框:
https://i.stack.imgur.com/b8keP.png
而已!
以上解决方案都没有帮助我。我正在处理一个旧项目,并且在我的计算机上全局安装了最新版本的 NodeJs(v14.x)。
没有高于 10.1.x 的节点版本对我有用,并且在测试时我收到与上述相同的错误。
解决方案
我安装了“n”,它是一个 nodeJs 版本管理器,比如 nvm
我将我的 nodeJs 版本降级到 9.x
npm install 现在可以工作了。
我现在需要更新我的版本,或者我的 package.json 中的 Specify my node version。
如果您已经安装了 XCode,您所要做的就是...
打开 XCode
转到 Xcode > 首选项 > 位置
从命令行工具中选择您的 XCode
不定期副业成功案例分享
/Applications/Xcode5-DP4.app
,我会假设。10.14.5
安装中,我安装了命令行工具 10.2.1,然后安装了 Xcode 10.2.1,并得到了上述错误。然后,我尝试使用此解决方案,但仍然出现上述错误。Franklin A
的解决方案有效:stackoverflow.com/a/40819686/9636