如何从命令行更新 Xcode

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

How to update Xcode from command line

xcode

提问by psvj

I am trying to update Xcode from the command line. Initially I tried running:

我正在尝试从命令行更新 Xcode。最初我尝试运行:

 xcode-select --install

which resulted in this message:

这导致了这条消息:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

So the question remains, is there a way to update Xcode from the command line?

所以问题仍然存在,有没有办法从命令行更新 Xcode?

回答by Vel Genov

What you are actually using is the command to install the Xcode command line tools - xcode-select --install. Hence the error message you got - the tools are already installed.

您实际使用的是安装 Xcode 命令行工具的命令 - xcode-select --install. 因此,您收到错误消息 - 工具已安装。

The command you need to update Xcode is softwareupdate command [args ...]. You can use softwareupdate --listto see what's available and then softwareupdate --install -ato install all updates or softwareupdate --install <product name>to install just the Xcode update (if available). You can get the name from the list command.

您需要更新 Xcode 的命令是softwareupdate command [args ...]. 您可以使用softwareupdate --list查看可用内容,然后softwareupdate --install -a安装所有更新或softwareupdate --install <product name>仅安装 Xcode 更新(如果可用)。您可以从 list 命令中获取名称。

As it was mentioned in the comments hereis the man page for the softwareupdatetool.

正如评论中提到的,这里是该softwareupdate工具的手册页。

2019 Update

2019年更新

A lot of users are experiencing problems where softwareupdate --install -awill in fact notupdate to the newest version of Xcode. The cause for this is more than likely a pending macOSupdate (as @brianlmerritt pointed out below). In most cases updating macOSfirst will solve the problem and allow Xcodeto be updated as well.

许多用户都遇到softwareupdate --install -a了实际上不会更新到最新版本Xcode 的问题。造成这种情况的原因很可能是未决的macOS更新(正如@brianlmerritt 在下面指出的那样)。在大多数情况下,首先更新macOS将解决问题并允许更新Xcode

Updating the Xcode Command Line Tools

更新 Xcode 命令行工具

A large portion of users are landing on this answer in an attempt to update the Xcode Command Line Tools. The easiest way to achieve this is by removing the old version of the tools, and installing the new one.

很大一部分用户登陆这个答案是为了更新Xcode Command Line Tools。实现这一目标的最简单方法是删除旧版本的工具,然后安装新版本。

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

A popup will appear and guide you through the rest of the process.

将出现一个弹出窗口并指导您完成其余的过程。

回答by ipinak

I had the same issue and I solved by doing the following:

我遇到了同样的问题,我通过执行以下操作解决了:

  1. removing the old tools ($ rm -rf /Library/Developer/CommandLineTools)
  2. install xcode command line tools again ($ xcode-select --install).
  1. 移除旧工具 ( $ rm -rf /Library/Developer/CommandLineTools)
  2. 再次安装 xcode 命令行工具 ( $ xcode-select --install)。

After these steps you will see a pop to install the new version of the tools.

完成这些步骤后,您将看到安装新版本工具的弹出窗口。

回答by Cyril Bouthors

I encountered the same issue when I uninstalled the complete version of Xcode to reinstall the CLI version. My fix was:

我在卸载完整版 Xcode 以重新安装 CLI 版本时遇到了同样的问题。我的解决方法是:

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

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

回答by Roy Huang

This saved my day. Just type the commands

这挽救了我的一天。只需输入命令

cd  /Library/Developer/CommandLineTools/Packages/;
open macOS_SDK_headers_for_macOS_10.14.pkg

Reference: https://forums.developer.apple.com/thread/104296

参考:https: //forums.developer.apple.com/thread/104296

回答by Navin

I got this error after deleting Xcode. I fixed it by resetting the command line tools path with sudo xcode-select -r.

删除Xcode后出现此错误。我通过重置命令行工具路径来修复它sudo xcode-select -r

Before:

前:

navin@Radiant ~$ /usr/bin/clang
xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.

navin@Radiant ~$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

After:

后:

navin@Radiant ~$ /usr/bin/clang
clang: error: no input files

回答by Minato

$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install

回答by brianlmerritt

@Vel Genov's answer is correct, except when the version of Xcode can't be updated because it is the latest version for your current version of Mac OS. If you know there is a newer Xcode (for example, it won't load an app onto a device with a recent version of iOS) then it's necessary to first upgrade Mac OS.

@Vel Genov 的回答是正确的,除非 Xcode 的版本无法更新,因为它是您当前版本的 Mac OS 的最新版本。如果您知道有更新的 Xcode(例如,它不会将应用程序加载到具有最新版本 iOS 的设备上),则有必要先升级 Mac OS。

Further note for those like me with old Mac Pro 5.1. Upgrading to Mojave required installing the metal gpu (Sapphire AMD Radeon RX 560 in my case) but make sure only HDMI monitor is installed (not 4K! 1080 only). Only then did install Mojave say firmware update required and shut computer down. Long 2 minute power button hold and it all upgraded fine after that!

对于像我这样使用旧 Mac Pro 5.1 的人,请进一步注意。升级到 Mojave 需要安装金属 GPU(在我的例子中是 Sapphire AMD Radeon RX 560),但确保只安装了 HDMI 显示器(不是 4K!1080)。然后才安装 Mojave 说需要固件更新并关闭计算机。长时间按住电源按钮 2 分钟,之后一切都升级了!

回答by RawBData

I was trying to use the React-Native Expo app with create-react-native-app but for some reason it would launch my simulator and just hang without loading the app. The above answer by ipinak above reset the Xcode CLI tools because attempting to update to most recent Xcode CLI was not working. the two commands are:

我试图将 React-Native Expo 应用程序与 create-react-native-app 一起使用,但由于某种原因,它会启动我的模拟器并且只是挂起而不加载应用程序。上面 ipinak 的上述回答重置了 Xcode CLI 工具,因为尝试更新到最新的 Xcode CLI 不起作用。这两个命令是:

rm -rf /Library/Developer/CommandLineTools
xcode-select --install

This process take time because of the download. I am leaving this here for any other would be searches for this specific React-Native Expo fix.

由于下载,此过程需要时间。我把这个留在这里,其他任何将搜索这个特定的 React-Native Expo 修复。

回答by Iuri Gavronski

After installing Command Line Tools (with xcode-select --install), type:

安装命令行工具(使用xcode-select --install)后,键入:

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

You should be able to run git now:

您现在应该可以运行 git:

10:29 $ git --version
git version 2.17.2 (Apple Git-113)

回答by obit

Xcode::Install is a simple cli software that allow you to install/select a specific Xcode version.

Xcode::Install 是一个简单的 cli 软件,允许您安装/选择特定的 Xcode 版本。

You can install it using gem install xcode-install
Then you will be able to install a specific version with xcversion install 9.4.1
And if you have more than one version installed, you can switch version with xcversion select 9.4

您可以使用安装它gem install xcode-install
然后您将能够使用安装特定版本xcversion install 9.4.1
如果您安装了多个版本,您可以使用切换版本xcversion select 9.4

You can find more information at https://github.com/KrauseFx/xcode-install

您可以在https://github.com/KrauseFx/xcode-install 上找到更多信息