How to switch xcode on Mac?
由于学习需要,我在MAC上装了两个版本的xcode,一个是xcode7.3,另一个是xcode8.3. 但在一些情况下我需要切换xcode的版本,于是自己摸索出以下经验。
1. 查看当前版本的xcode
/usr/bin/cc --version
我这里是:
jhmdeiMac:~ jhm$ /usr/bin/cc --version
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
可以看出,我当前版本是xcode7.3.0
2. 切换xcode版本
首先看切换的命令:xcode-select
jhmdeiMac:~ jhm$ xcode-select -h
Usage: xcode-select [options]
Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).
Options:
-h, --help print this help message and exit
-p, --print-path print the path of the active developer directory
-s <path>, --switch <path> set the path for the active developer directory
--install open a dialog for installation of the command line developer tools
-v, --version print the xcode-select version
-r, --reset reset to the default command line tools path
接下来,我们用命令行来切换xcode版本。
sudo xcode-select --switch /Library/Developer/CommandLineTools
当然,要在打命令之前知道自己其他的xcode版本的位置。
用/usr/bin/cc –version来检查是否改变了版本。
jhmdeiMac:~ jhm$ /usr/bin/cc --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin