更改xcrun开发者路径

67

我该如何更改 xcrun 指向的目录?当前指向的目录为:

xcrun: 错误:无法查找活动的 Xcode 路径 '/Volumes/Xcode/Xcode44-DP7.app/Contents/Developer'。 (没有这个文件或目录)

我需要更改此位置。谢谢。

11个回答

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

非常感谢你,亲爱的。这帮了我大忙。 - Ganesh G
谢谢,太棒了! - Atef
这很有趣:这会改变整个系统的Xcode版本,是否可能在特定的构建过程中进行选择...?我有一个使用案例,其中并行构建正在运行...全局更改对我没有帮助.. - Sreedhar GS

45

使用 xcode-select -switch 命令来选择默认使用的 Xcode 版本。


2
在OSX Yosemite上使用xcode-select --switch path/to/Xcode.app - Antonio
请尝试以下操作:
  1. xcode-select --install
  2. sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
- Teja Swaroop

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

这就是我的经历。当我从我的Mac卸载Xcode时,Git不再工作了。我只需执行这行代码,而无需重新安装Xcode,一切就恢复正常了。 - TiMESPLiNTER

14

在我的情况下,我需要:

  1. 安装Xcode的命令行工具,进入“偏好设置” -> “位置”,并为“命令行工具”设置正确的值。
  2. 在“下载” -> “组件”选项卡中,点击名为“命令行工具”的一行上的安装按钮。
  3. Marmalade与Xcode正常配合工作。

这对我来说是答案,如果您没有设置命令行工具,那么这也适用于您。 - Tristan Warner-Smith

11

如果您运行此命令:

$ xcode-select -p

它将在屏幕上打印如下:

/Volumes/Xcode/Xcode44-DP7.app/Contents/Developer (在您的情况下)

要将其更改为默认设置,您可以按照以下步骤进行操作:

$ sudo xcode-select -r
Password:

请再次确认:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

了解更多信息请访问:

$ xcode-select

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
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path

10

打开Xcode并导航到偏好设置...

在此输入图像描述

从命令行工具中选择Xcode的位置。

在此输入图像描述 之后从终端执行命令。


7

或者,可以覆盖DEVELOPER_DIR环境变量:

export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"

此设置对每个用户帐户是唯一的。如果存在,则会覆盖 xcode-select 的选择。

可选:您可以通过编辑您的 .bash_profile 文件使其在登录会话之间持久化。


4

您无需安装Xcode即可使用xcrun。

只需安装Xcode命令行工具并切换到它即可。

安装Xcode命令行工具。

xcode-select --install

切换到命令行工具

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

2

卸载Xcode后怎么办?

在控制台中运行以下命令:

sudo xcode-select --reset

1

我正在尝试通过终端获取Git克隆。

  1. User-Mac-mini:~ user_name$ cd /Users/yser_name/Documents/Developer/Xcode_Projects/Xcode_Proj/AAG/EJ

  2. user-Mac-mini:EJ user_name$ git clone https://smaplebitbucket.org/projectname/sample.git

我收到以下错误:

xcrun: error: active developer path ("/Applications/Xcode 8.app/Contents/Developer") does not exist, use `xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools (or see `man xcode-select`)

起初我有两个Xcode 7.3和8.0。我将7.0的名字命名为xcode,将8.0的名字命名为xcode 8

我从应用程序中删除了7.0的xcode并将xcode 8重命名为xcode
在Xcode首选项中,它指向的位置是xcode 8,但实际上它不存在。

我使用以下命令更改了位置:

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

Git命令已经生效,我能够从GIT下载项目。您也可以从Xcode偏好设置中完成此操作。

enter image description here

它起作用了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接