如何从 xip 文件安装 Xcode

How to install Xcode from xip file

我是 macOS 的新手,我只需要 mac 和 Xcode 来编译我的应用程序。但是,使用 macOS Sierra,我的 USB 出现问题,无法正常工作(我无法插入 ipad pro)

在 OSX el capitan 下我的 usb 工作得很好,但现在的问题是应用商店让我下载只能在 Sierra 上工作的 Xcode 8.3(很奇怪他们给你下载与您的系统不兼容但没关系的东西,这是苹果)。所以我唯一的办法就是手动下载 xcode 8.2.1

现在我的问题是,如何安装我刚刚下载的Xcode_8.2.1.xip?并且在不久的将来,如果我需要更新xcode(我想自己下载一个新版本),我该怎么办?还有首选项和配置设置保存在哪里?这些首选项是否会在每次更新时丢失?

双击 xip 文件,它将提取 Xcode 应用程序。将 Xcode 移动到 Applications 文件夹,您就可以开始了。

一旦您更新到 Sierra (macOS 10.12),App Store 应该会显示 Xcode 更新。如果没有,您可以直接从 App Store 下载 Xcode。首选项存储在 /Users/<username>/Library/Preferences 中,不受更新 Xcode 或 OS.

版本的影响

例如,如果 XIP 文件位于您的桌面上:打开 /Applications/Utilities/ 中的“终端”应用程序和 运行 以下命令:

 xip -x ~/Desktop/Xcode_8.2.1.xip

更新:2020 年 5 月 17 日:最简单的方法

- Download the specific Xcode version that you want [from here][1]
- Add the downloaded Xcode.xip in Applications 
- Double click on it, it will start expand. It will take some time.
- If you have multiple Xcode version like 12.0, 12.1 in Applications rename it accordingly.
- Double click on extracted Xcode version and install tools.
- To set default Xcode version run this command: 

    sudo xcode-select -switch /Applications/Xcode_12.1.app

- To check default Xcode version in your system use this command:

    /usr/bin/xcodebuild -version

注意:如果您在应用程序中没有多个 xcode 版本,则可以跳过设置默认 xcode 步骤。

更新:2020 年 10 月 8 日:简单方法

旧答案

通过打开终端到放置 xip 的文件夹并运行以下命令将 xip 转换为 dmg:

$ open Xcode_X_Y_Z.xip
  $ mkdir Xcode-tmp
  $ mv Xcode.app Xcode-tmp/Xcode.app
  $ hdiutil create -volname "Xcode" \
            -srcfolder Xcode-tmp \
            -ov -format UDZO \
            Xcode_X.Y.Z.dmg
  $ rm -rf Xcode-tmp