如何更新 Xcode 命令行工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42538171/
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-08 18:25:06  来源:igfitidea点击:

How to update Xcode Command Line Tools?

xcodemacosxcode-command-line-tools

提问by Akshay Khot

I am trying to update Command line tools on my mac osx.

我正在尝试更新我的 mac osx 上的命令行工具。

~  softwareupdate --list
Software Update Tool
Copyright 2002-2015 Apple Inc.

Finding available software
Software Update found the following new or updated software:

   * Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2
    Command Line Tools (macOS El Capitan version 10.11) for Xcode (8.2), 150374K [recommended]
   * iTunesX-12.5.5
    iTunes (12.5.5), 263476K [recommended]

But when I run the update command, I get this error:

但是当我运行更新命令时,我收到此错误:

softwareupdate -i Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2
zsh: number expected

This doesn't work either:

这也不起作用:

softwareupdate -i Command Line Tools
Software Update Tool
Copyright 2002-2015 Apple Inc.

Command: No such update
Line: No such update
Tools: No such update
No updates are available.

What is the exact string I should specify after sofwareupdate -i?

我应该在之后指定的确切字符串是什么 sofwareupdate -i?

回答by M Falanga

For future travelers, here's a version-agnostic approach. First, run softwareupdate --list. This will probably take a couple of minutes. When it's done, you'll see a bulleted (with an asterisk) output like this:

对于未来的旅行者,这是一种与版本无关的方法。首先,运行softwareupdate --list。这可能需要几分钟。完成后,您将看到如下所示的项目符号(带有星号)输出:

$ softwareupdate --list
Software Update Tool

Finding available software
Software Update found the following new or updated software:
   * Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.1
        Command Line Tools (macOS High Sierra version 10.13) for Xcode (10.1), 190584K [recommended]

Find the bullet that refers to the Xcode command line tools. Copy that entire line (except the asterisk...). In the above case, you would copy: Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.1

找到引用 Xcode 命令行工具的项目符号。复制整行(星号除外...)。在上述情况下,您将复制:Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.1

Then, run the install command (as shown by Brendan Shanks) with what you copied inside quotes:

然后,使用您在引号内复制的内容运行安装命令(如 Brendan Shanks 所示):

softwareupdate -i "Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.1"

回答by Cris Luengo

I'm going to answer a slightly different question here, because this question came up when I searched for a solution to my problem. Hopefully it'll help someone (and it'll surely help me next time I run into the same issue).

我将在这里回答一个略有不同的问题,因为当我搜索问题的解决方案时出现了这个问题。希望它会帮助某人(下次我遇到同样的问题时它肯定会帮助我)。

I wanted to upgrade the command line tools from version 8 to 9. The App Store didn't suggest this upgrade, and neither did softwareupdate --list.

我想将命令行工具从版本 8 升级到 9。App Store 没有建议升级,softwareupdate --list.

xcode-select --install

installed the new version of the tools. But clang --versionstill gave 8.0.0 as the version number. xcode-select -rand rebooting didn't solve this issue.

安装了新版本的工具。但是clang --version还是给了 8.0.0 作为版本号。xcode-select -r并且重新启动并没有解决这个问题。

xcode-select -preturned /Applications/Xcode.app/Contents/Developer, and clang --versionreported an installation directory under there. I thought I'd start over again.

xcode-select -p返回/Applications/Xcode.app/Contents/Developer,并clang --version在那里报告了一个安装目录。我以为我会重新开始。

sudo rm -rf /Applications/Xcode.app

deleted version 8 of the tools. But xcode-select --installsaid the command line tools were already installed.

删除了第 8 版的工具。但是xcode-select --install说命令行工具已经安装好了。

sudo xcode-select -r

Now, sudo xcode-select -preturns /Library/Developer/CommandLineTools/.

现在,sudo xcode-select -p返回/Library/Developer/CommandLineTools/

It seems that the problem was that the new version of the tools are installed to a different directory, and xcode-select -ris not clever enough to find the latest version.

问题似乎是新版本的工具安装到了不同的目录,xcode-select -r不够聪明,找不到最新版本。

回答by Brendan Shanks

Run softwareupdate -i "Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2". The quotes are important.

运行softwareupdate -i "Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2"。引号很重要。

回答by Hanny

I faced similar problem on MacOS Mojave version 10.14.3with Xcode 10.3installed. The real problem was, when I installed the Xcode 10.3, I deleted the "Xcode-beta.app" first and then installed the new version. Therefore, when I tried installing CLion for C++ development and configuring it, CMakegave me error And Updating Command Line Tool didnt work for me:

我在安装了Xcode 10.3 的MacOS Mojave 版本 10.14.3上遇到了类似的问题。真正的问题是,当我安装Xcode 10.3 时,我先删除了“ Xcode-beta.app”,然后安装了新版本。因此,当我尝试为 C++ 开发安装 CLion 并对其进行配置时,CMake给了我错误并且更新命令行工具对我不起作用:

softwareupdate -i "Command Line Tools (macOS Mojave version 10.14.3) for Xcode-10.3"

and showed me this response in terminal

并在终端中向我展示了这个响应

Software Update Tool
Command Line Tools (macOS Mojave version 10.14.3) for Xcode-10.3: No such update
No updates are available.

Then I tried to check the version of Clang using:

然后我尝试使用以下方法检查 Clang 的版本:

clang --version

And the response lead me to the real problem i.e. Active Developer path was still pointing to Old version of Xcode that I had already deleted.

响应将我引向了真正的问题,即 Active Developer 路径仍然指向我已经删除的旧版本 Xcode。

xcrun: error: active developer path ("/Applications/Xcode-beta.app/Contents/Developer") does not exist

Therefore, I switched the active developer path to latest Xcode App installed using:

因此,我将活动开发人员路径切换到使用以下方法安装的最新 Xcode App:

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

And everything worked like a charm automatically.

一切都像魅力一样自动运行。

回答by Akshay Khot

I ran the same command with sudoand that did the trick.

我运行了相同的命令sudo,就成功了。

sudo softwareupdate -i "Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2"

sudo softwareupdate -i "Command Line Tools (macOS El Capitan version 10.11) for Xcode-8.2"

回答by bjelli

when upgrading to MacOS Catalina, Version 10.15.* you can install the command line tools for xcode 11.3 like this:

升级到 MacOS Catalina 版本 10.15.* 时,您可以像这样安装 xcode 11.3 的命令行工具:

$ softwareupdate --list
Software Update Tool

Finding available software
Software Update found the following new or updated software:
* Label: Command Line Tools for Xcode-11.3
    Title: Command Line Tools for Xcode, Version: 11.3, Size: 224878K, Recommended: YES,
$ sudo softwareupdate -i "Command Line Tools for Xcode-11.3"