使用多个版本的Xcode

示例

您可以同时安装多个版本的Xcode(包括Beta版)。只需在Finder中重命名应用程序即可避免冲突。

注意:从App Store安装Xcode往往会覆盖计算机上的现有版本。您也可以直接下载安装Xcode,以更好地控制所拥有的版本。

Xcode中的每个拷贝包括命令行工具(clang,xcodebuild等)。您可以选择中的命令调用哪些命令/usr/bin。

在Xcode的首选项中,在“位置”选项卡下,选择一个Xcode版本:

或者,您可以使用xcode-select以下命令从命令行管理版本:

# Print the currently selected version
$ xcode-select --print-path/Applications/Xcode.app/Contents/Developer

$ clang --versionApple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

# Find all installed versions using Spotlight
$ mdfind 'kMDItemCFBundleIdentifier = "com.apple.dt.Xcode"'/Applications/Xcode.app
/Applications/Xcode72.app

# Check their version numbers
$ mdfind 'kMDItemCFBundleIdentifier = "com.apple.dt.Xcode"' | xargs mdls -name kMDItemVersionkMDItemVersion = "7.3"
kMDItemVersion = "7.2.1"

# Switch to a different version
$ sudo xcode-select --switch /Applications/Xcode72.app$ clang --versionApple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.4.0
Thread model: posix