安装和切换多个 Xcode 版本的最佳命令行工具。
如果您正在寻找 xcodes
的应用程序版本,请尝试 Xcodes.app。
Xcodes 现在是 XcodesOrg
的一部分 - 在此处阅读更多信息
brew install xcodesorg/made/xcodes
这些是经过开发者 ID 签名和公证的发布版本,无需预先安装 Xcode 即可使用。
其他方法
从 发布 页面下载最新版本。这些是经过开发者 ID 签名的发布版本,无需预先安装 Xcode 即可使用。
mint install XcodesOrg/xcodes
从源代码构建需要 Xcode 12.0 或更高版本,因此不适合从头开始设置计算机。
git clone https://github.com/XcodesOrg/xcodes
cd xcodes
make install
# or, if /usr/local/ isn't in your PATH
PREFIX=/your/install/directory make install
安装时,您可能会看到以下输出
swift build
error: terminated(72): xcrun --sdk macosx --find xctest output:
如果发生这种情况,则表示您需要选择一个 Xcode 版本。您可以使用 xcode-select
或在 Xcode 的偏好设置的“位置”选项卡中选择“命令行工具”选项来执行此操作。
使用类似以下命令之一安装特定版本的 Xcode
xcodes install 10.2.1
xcodes install 11 Beta 7
xcodes install 11.2 GM seed
xcodes install 9.0 --path ~/Archive/Xcode_9.xip
xcodes install --latest-prerelease
xcodes install --latest --directory "/Volumes/Bag Of Holding/"
xcodes install --latest --experimental-unxip
然后,系统将提示您输入 Apple ID 用户名和密码。您还可以使用 XCODES_USERNAME
和 XCODES_PASSWORD
环境变量提供这些信息。
成功通过身份验证后,xcodes 会将您的 Apple ID 密码保存到钥匙串中,并在以后记住您的 Apple ID 以供使用。如果您需要使用与记住的 Apple ID 不同的 Apple ID,请设置 XCODES_USERNAME
环境变量。
xcodes 将下载并安装您要求的版本,以便您随时可以使用。
(1/6) Downloading Xcode 11.2.0: 100%
(2/6) Unarchiving Xcode (This can take a while)
(3/6) Moving Xcode to /Applications/Xcode-11.2.0.app
(4/6) Moving Xcode archive Xcode-11.2.0.xip to the Trash
(5/6) Checking security assessment and code signing
(6/6) Finishing installation
xcodes requires superuser privileges in order to finish installation.
macOS User Password:
Xcode 11.2.0 has been installed to /Applications/Xcode-11.2.0.app
如果您已安装 aria2(可在 Homebrew 中找到,brew install aria2
),则 xcodes 默认使用它进行下载。它使用多达 16 个连接来下载 Xcode,速度比 URLSession 快 3-5 倍。
Xcode 默认安装到 /Applications,但您可以使用 --directory
选项或 XCODES_DIRECTORY
环境变量为不同的目录提供路径。 所有 xcodes 命令都支持此选项,例如 select
和 uninstall
,因此您可以管理不在 /Applications 中的 Xcode 版本。xcodes 支持将所有 Xcode 版本安装在一个目录中,无论该目录在哪里。
运行此命令行以显示可用的运行时
xcodes runtimes --include-betas
安装所需的运行时(例如 iOS 17.0-beta1)
xcodes runtimes install "iOS 17.0-beta1"
我们建议创建一个 .xcode-version
文件,以明确声明和存储您的 CI 环境和团队要使用的 Xcode 版本。
13.4.1
阅读 .xcode-version
的 提案。
download <version>
:下载特定版本的 Xcodeinstall <version>
:下载并安装特定版本的 Xcodeinstalled
:列出已安装的 Xcode 版本list
:列出所有可供安装的 Xcode 版本select
:更改所选的 Xcodeuninstall
:卸载特定版本的 Xcodeupdate
:更新可用 Xcode 版本的列表version
:打印 xcodes 自身的版本号signout
:清除存储的用户名和密码感谢 saagarjhi 的出色工作 - Xcodes 现在包含 unxip 功能,在某些系统上,解压缩速度最高可提高 70%。
xcodes install --latest --experimental-unxip
xcodes 可以生成补全脚本,允许您在键入 xcodes 命令时按键盘上的 Tab 键来自动补全命令和参数。 安装补全脚本的步骤取决于您使用的 shell。 有关不同 shell 的安装说明和底层实现的更多信息,请参见 swift-argument-parser repo。
运行以下命令
mkdir ~/.oh-my-zsh/completions
xcodes --generate-completion-script > ~/.oh-my-zsh/completions/_xcodes
您需要 Xcode 13 才能构建和运行 xcodes。
从 Xcode 运行 xcodes 时,如果要运行特定命令或传递一些参数,您可以按住 Option 键来显示包含更多选项的表单。 这意味着您将使用 Option + Command + R 或在单击“运行”按钮时按住 Option。 在这里,您可以添加、删除和切换将在启动 xcodes 时传递给它的参数。
swift build
swift run
,或命令如 swift run xcodes list
swift test
有一个 Makefile 可以帮助构建 xcodes 以进行分发。 为了通过 Homebrew 提供开发者 ID 签名和公证的发布版本,我们已经为您完成了此操作(请参阅 安装)。
# Bump the version number in Version.swift, commit the change, and tag it
vim Sources/XcodesKit/Version.swift
git add Sources/XcodesKit/Version.swift
git commit -m "Bump version to $VERSION"
git tag -asm "$VERSION" "$VERSION"
# Clean first
make clean
# Make a release build of xcodes, sign it, and zip it
make zip
# Create a Homebrew bottle
make bottle VERSION="$VERSION"
# Notarize the release build
# This can take a while
make notarize \
TEAMID="ABC123"
# Push the new version bump commit and tag
git push --follow-tags
# Edit the draft release created by Release Drafter to point at the new tag
# Set the release title to the new version
# Duplicate xcodes-$VERSION.mojave.tar.gz and rename to xcodes-$VERSION.arm64_mojave.tar.gz
# Add the xcodes.zip, xcodes-$VERSION.mojave.tar.gz, xcodes-$VERSION.arm64_mojave.tar.gz files to the release
# Publish the release
# Update the Homebrew Bottle: https://github.com/XcodesOrg/homebrew-made/blob/master/Formula/xcodes.rb
值得注意的设计决策记录在 DECISIONS.md 中。 Apple 身份验证流程在 Apple.paw 中进行了描述,这将允许您使用 Paw 应用程序来玩涉及到的 API 端点。
xcode-install
和 fastlane/spaceship 都值得赞扬,因为它们弄清了使这成为可能的困难部分。