简体   繁体   English

如何在 Mac OS X 中的多个命令行工具安装之间切换(不安装 XCode)

[英]How to switch between multiple Command Line Tools installations in Mac OS X (without installing XCode)

Is it possible to install and switch between multiple version of Command Line Tools in Mac OS X?是否可以在 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.我想知道是否可以使用xcode-select但命令行工具安装程序没有选择安装目标的选项。 I tried to create multiple installations by manually renaming Library/Developer/CommandLineTools and then passing it to xcode-select .我尝试通过手动重命名Library/Developer/CommandLineTools然后将其传递给xcode-select来创建多个安装。 The command succeeds but when I try to access gcc I get:命令成功,但是当我尝试访问 gcc 时,我得到:

gcc: error: unable to find Xcode installation from active developer path "/Library/Developer/CommandLineTools_9.0.0", use xcode-select to change

It seems this is possible when installing the whole XCode but I have no need for XCode and prefer not to install it.在安装整个 XCode 时,这似乎是可能的,但我不需要 XCode,也不想安装它。 All I need is the command line tools.我只需要命令行工具。

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.是的,这是可能的,但您需要复制/重命名整个/Library/Developer文件夹。 For example:例如:

1) first, I just show my macOS version: 1) 首先,我只展示我的 macOS 版本:

$ sw_vers 
ProductName:    Mac OS X
ProductVersion: 10.13.6
BuildVersion:   17G65

2) download and install Command Line Tools for Xcode, eg 10b5 version 2) 下载并安装 Xcode 的命令行工具,例如 10b5 版本

3) create folders to store different versions of tools: 3)创建文件夹来存放不同版本的工具:

$ mkdir ~/Project/tools
$ mkdir ~/Projects/tools/Developer10b5
$ mkdir ~/Projects/tools/Developer9.4.1

4) copy the whole Developer folder: 4)复制整个Developer文件夹:

$ cp -R /Library/Developer/ ~/Project/tools/Developer10b5/

5) then, download and install Command Line Tools for Xcode, eg 9.4.1 version 5) 然后,下载并安装 Xcode 的命令行工具,例如 9.4.1 版本

6) copy the whole Developer folder: 6)复制整个Developer文件夹:

$ cp -R /Library/Developer/ ~/Project/tools/Developer9.4.1/

7) switch to 9.4.1 version of tools and check the clang version: 7)切换到9.4.1版本的工具,查看clang版本:

$ 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) switch to 10b5 version of tools and check the clang version: 8)切换到10b5版本的工具,查看clang版本:

$ 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

For those who have a problem like as @PaulMasri-Stone, I found that after removing a previously installed Xcode (installing multiple versions of Xcode was not an option on my computer because of space), the method above also gave me the 'invalid developer directory' error.对于那些像@PaulMasri-Stone 这样有问题的人,我发现在删除以前安装的 Xcode 后(由于空间原因,我的计算机上无法安装多个版本的 Xcode),上面的方法也给了我“无效的开发人员”目录”错误。

I overcame this problem by typing sudo xcode-select -r to reset to the default command-line tools (and reset whatever other underlying state that the system uses to track the SDK location -- and lack of Xcode), followed by sudo xcode-select -s /Library/Developer/CommandLineTools10.13_Xcode9.4.1 .我通过键入sudo xcode-select -r重置为默认命令行工具(并重置系统用于跟踪 SDK 位置的任何其他底层状态 - 以及缺少 Xcode),然后sudo xcode-select -s /Library/Developer/CommandLineTools10.13_Xcode9.4.1 Note that sudo xcode-select -s /Library/Developer would not work for me, just like the problem that @PaulMasri-Stone had.需要注意的是sudo xcode-select -s /Library/Developer会为我工作,就像问题@ PaulMasri石了。

Otherwise, you will want to follow the instructions that @Ilirium specified, but you only need to copy/rename the CommandLineTools directory.否则,您将需要按照@Ilirium 指定的说明进行操作,但您只需复制/重命名CommandLineTools目录。

These instructions worked for me.这些说明对我有用。 @PaulMasri-Stone - Instead of pointing xcode to the root directory, I had to point it to the CommandLineTools directory like so: @PaulMasri-Stone - 我没有将 xcode 指向根目录,而是将它指向 CommandLineTools 目录,如下所示:

sudo xcode-select -s ~/projects/tools/llvm1131/CommandLineTools/须藤 xcode-select -s ~/projects/tools/llvm1131/CommandLineTools/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM