xcode 无法在安装了命令行工具的 Mavericks 上使用 xcodebuild

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19605862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:59:16  来源:igfitidea点击:

Unable to use xcodebuild on Mavericks with Command Line Tools installed

xcodemacosoperating-systemosx-mavericks

提问by

I have installed the Command Line Tools:

我已经安装了命令行工具:

$ xcode-select --print-path
/Library/Developer/CommandLineTools

However, when anything tries to use xcodebuild, I get the following error:

但是,当任何尝试使用时xcodebuild,我收到以下错误:

$ /usr/bin/xcodebuild
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

On Mountain Lion it was possible to use this without installing the whole of Xcode, rather just the Command Line Tools. Is it possible to do this on Mavericks? How can I get it working?

在 Mountain Lion 上,可以在不安装整个 Xcode 的情况下使用它,而只需安装命令行工具。可以在小牛队上做到这一点吗?我怎样才能让它工作?

N.B. This is on a clean installof Mavericks.

注意这是在Mavericks 的全新安装上。

Update:just to show, I do have the Command Line Tools installed:

更新:只是为了显示,我确实安装了命令行工具:

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

回答by Juanan

I know that this is a late answer, but in my case this command solved the issue:

我知道这是一个迟到的答案,但就我而言,这个命令解决了这个问题:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

回答by loganfsmyth

It appears that OSX has changed xcodebuildto require XCodeto be installed, where before it functioned properly with only the OSX Command Line Tools installed.

似乎 OSX 已更改xcodebuild为需要XCode安装,而之前仅安装了 OSX 命令行工具即可正常运行。

Old semi-related answer

旧的半相关答案

Many people ran into this with Node. Node's build tool, gyp, uses xcodebuildto prepare for compiling node packages. Mavericks has changed the behavior of xcodebuildso that it no longer works properly with gyp. This is being fixed at the moment. See the node-gyp issue

许多人在使用 Node.js 时遇到了这个问题。节点的构建工具,gyp,使用xcodebuild用于编译节点包准备。Mavericks 已更改 的行为xcodebuild,使其不再与gyp. 目前正在修复此问题。查看 node-gyp 问题

Once the changes have been deployed to NPM, you will be able to install the new node-gyppackage and compile properly. You will also need to update your NPM version once the changes are incorporated into NPM.

将更改部署到 NPM 后,您将能够安装新node-gyp包并正确编译。一旦将更改合并到 NPM 中,您还需要更新 NPM 版本。

回答by Muhammed Irfan

Please first go to finder, next select Applications from left panel, next look for Xcode, and check if its name is Xcode or Xcode-Beta

请先到 finder,然后从左侧面板中选择 Applications,然后查找 Xcode,然后检查它的名称是 Xcode 还是 Xcode-Beta

If name is Xcode-Beta then enter this command in Terminal:

如果名称是 Xcode-Beta,则在终端中输入以下命令:

sudo xcode-select -switch /Applications/Xcode-Beta.app/Contents/Developer

If name is Xcode then enter this command:

如果名称是 Xcode,则输入以下命令:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Hope this answer might help for users with Beta version of Xcode

希望这个答案对使用 Beta 版 Xcode 的用户有所帮助

Thanks

谢谢

回答by carlodurso

This issue was due to xcode-select developer directorypointing to /Library/Developer, which only contained the folder CommandLineTools. To this end, the error message is complaining about not the directory not being the same as Xcode.

此问题是由于 xcode-select开发人员目录指向/Library/Developer,其中仅包含文件夹CommandLineTools. 为此,错误消息抱怨目录与 Xcode 不同。

Two tested solutions:

两种经过测试的解决方案:

  1. (Re) Install Xcode.

  2. Point xcode-select to the Xcode Developer Directoryusing the following command:

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    
  1. (重新)安装Xcode。

  2. 使用以下命令将 xcode-select 指向Xcode Developer Directory

    sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
    


References:

参考:

How to fix error like “xcode-select: error: tool ‘xcodebuild' requires Xcode, but active developer directory* BROKEN LINK *

如何修复诸如“xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory* BROKEN LINK * 之类的错误

xcode-select active developer directory error

xcode-select 活动开发者目录错误

回答by zinking

I reinstalled Xcode from App Store which solved this issue. I guess my previous installation is not complete install

我从 App Store 重新安装了 Xcode,解决了这个问题。我猜我之前的安装是不完整的安装

回答by turibbio

If you use XCode2: sudo xcode-select --switch /Applications/Xcode\ 2.app/Contents/Developer

如果您使用 XCode2: sudo xcode-select --switch /Applications/Xcode\ 2.app/Contents/Developer

Pay attention to the "\" to escape the space.

注意“\”以逃避空格。

回答by AnneTheAgile

Today I had this issue and the problem was I was using a manual install of xcode and had the file named Xcode8.3.2.app instead of Xcode.app. Renaming the app fixed the issue of xcode-select complaining. This seems to indicate the regular appname is on its search path but variants are not.

今天我遇到了这个问题,问题是我使用的是手动安装的 xcode 并且文件名为 Xcode8.3.2.app 而不是 Xcode.app。重命名应用程序修复了 xcode-select 抱怨的问题。这似乎表明常规 appname 在其搜索路径上,但变体不在。

回答by suite22

There's also a GUI to change the Command Line Tools path in Xcode > Preferences > Locations:

还有一个 GUI 可以在 Xcode > Preferences > Locations 中更改命令行工具路径:

Xcode >Preferences >Locations

Xcode >首选项 >位置

I just had this issue after upgrading to Xcode 10.3 while keeping an older copy of 10.2.1 in a sub-folder in Applications. When I opened this Locations panel the selection for Command Line Tools was blank, but I was able to choose between the two versions installed:

升级到 Xcode 10.3 后,我刚刚遇到了这个问题,同时在 Applications 的子文件夹中保留了 10.2.1 的旧副本。当我打开这个位置面板时,命令行工具的选择是空白的,但我可以在安装的两个版本之间进行选择:

Command Line Tools selection dropdown

命令行工具选择下拉菜单

I tend to go with the GUI option if it's available instead of copying in sudocommands from SO.

如果可用,我倾向于使用 GUI 选项,而不是sudo从 SO复制命令。

回答by moreaug44

AFAIK, command line tools in Mavericks are installed into /Applications/Xcode.app/Contents/Developer which tends to imply that Xcode is required. Undocumented feature probably.

AFAIK,Mavericks 中的命令行工具安装在 /Applications/Xcode.app/Contents/Developer 中,这意味着需要 Xcode。可能未记录的功能。