在运行npm安装时看到以下错误,需要node-gyp…但可以被任何需要xcode-select的东西触发。

xcodebuild工具需要Xcode,但是是活动的 开发者目录'/Library/ developer /CommandLineTools'是一个命令 直线工具实例

有什么问题吗?


当前回答

只需运行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.

其他回答

手动安装Command LineTool对我来说很有效。

我在App Store中暂停了xcode 仍然无法下载Homebrew 我通过链接手动安装命令行工具。 砰砰砰

https://developer.apple.com/download/more/?=command%20line%20tools

我在高海拔地区也遇到了同样的问题。 运行下面的命令可以解决这个问题

npm explore npm -g -- npm install node-gyp@latest

我得先运行这个

sudo xcode-select --reset

then

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

然后就成功了。

我无需安装完整的Xcode应用程序就可以解决这个错误。但是,你必须安装xcode命令行工具。

从这里开始:

$ 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

当需要一个完整的常规Xcode时,Xcode -select developer目录指向/Library/ developer /CommandLineTools时发生此问题(当CommandLineTools安装在Xcode之后时发生)

解决方案:

如果你还没有Xcode,请安装它(从https://appstore.com/mac/apple/xcode获取)。 接受条款和条件。 确保Xcode app在/Applications目录下(不是/Users/{user}/Applications)。 使用以下命令将Xcode -select指向Xcode app Developer目录: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

注意:确保你的Xcode应用路径是正确的。

Xcode: / / Xcode /内容/应用开发者 Xcode-beta: / / Xcode-beta.app /内容/应用开发者