如何在Mac OS X中的多个命令行工具安装之间切换(不安装XCode) [英] How to switch between multiple Command Line Tools installations in Mac OS X (without installing XCode)
问题描述
在Mac OS X中是否可以在多个版本的命令行工具之间安装和切换?我想知道是否可以使用xcode-select
,但是命令行工具安装程序没有选择安装目标的选项.我尝试通过手动重命名Library/Developer/CommandLineTools
并将其传递给xcode-select
来创建多个安装.该命令成功执行,但是当我尝试访问gcc时,我得到了:
Is it possible to install and switch between multiple version of Command Line Tools in Mac OS X? I was wondering if it's possible use xcode-select
but the Command Line Tools installer doesn't have an option to choose the installation destination. I tried to create multiple installations by manually renaming Library/Developer/CommandLineTools
and then passing it to xcode-select
. The command succeeds but when I try to access gcc I get:
gcc: error: unable to find Xcode installation from active developer path "/Library/Developer/CommandLineTools_9.0.0", use xcode-select to change
gcc: error: unable to find Xcode installation from active developer path "/Library/Developer/CommandLineTools_9.0.0", use xcode-select to change
在安装整个XCode时似乎有可能,但是我不需要XCode且宁愿不安装它.我需要的只是命令行工具.
It seems this is possible when installing the whole XCode but I have no need for XCode and prefer not to install it. All I need is the command line tools.
推荐答案
我尝试做同样的事情,经过一些实验,找到了下一个解决方案.是的,可以,但是您需要复制/重命名整个/Library/Developer
文件夹.例如:
I tried to do the same and after some experiments found the next solution. Yes, it is possible but you need to copy/rename the whole /Library/Developer
folder. For example:
1)首先,我只显示我的macOS版本:
1) first, I just show my macOS version:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.13.6
BuildVersion: 17G65
2)下载并安装Xcode的命令行工具,例如10b5版本
2) download and install Command Line Tools for Xcode, e.g. 10b5 version
3)创建文件夹以存储不同版本的工具:
3) create folders to store different versions of tools:
$ mkdir ~/Project/tools
$ mkdir ~/Projects/tools/Developer10b5
$ mkdir ~/Projects/tools/Developer9.4.1
4)复制整个Developer文件夹:
4) copy the whole Developer folder:
$ cp -R /Library/Developer/ ~/Project/tools/Developer10b5/
5),然后下载并安装Xcode的命令行工具,例如9.4.1版本
5) then, download and install Command Line Tools for Xcode, e.g. 9.4.1 version
6)复制整个Developer文件夹:
6) copy the whole Developer folder:
$ cp -R /Library/Developer/ ~/Project/tools/Developer9.4.1/
7)切换到9.4.1版本的工具并检查clang版本:
7) switch to 9.4.1 version of tools and check the clang version:
$ sudo xcode-select -s ~/Project/tools/Developer9.4.1/
$ clang --version
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Users/<username>/Projects/tools/Developer9.4.1/CommandLineTools/usr/bin
8)切换到10b5版本的工具并检查clang版本:
8) switch to 10b5 version of tools and check the clang version:
$ clang --version
Apple LLVM version 10.0.0 (clang-1000.10.40.1)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Users/<username>/Projects/tools/Developer10b5/CommandLineTools/usr/bin
这篇关于如何在Mac OS X中的多个命令行工具安装之间切换(不安装XCode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!