5

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

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.

Milad
  • 4,901
  • 5
  • 32
  • 43

3 Answers3

6

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) first, I just show my macOS version:

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

2) download and install Command Line Tools for Xcode, e.g. 10b5 version

3) create folders to store different versions of tools:

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

4) copy the whole Developer folder:

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

5) then, download and install Command Line Tools for Xcode, e.g. 9.4.1 version

6) copy the whole Developer folder:

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

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) 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
Ilirium
  • 71
  • 1
  • 8
  • I've followed your instructions but the `sudo xcode-select` statements give me the error `invalid developer directory`. Any ideas? – Paul Masri-Stone Feb 11 '19 at 15:23
  • @PaulMasri-Stone Could you write the statement with flags and arguments which you used? It is possible that a folder which you specified doesn't contain Command Line Tools for Xcode. – Ilirium Feb 21 '19 at 02:47
  • Sorry I can’t. I gave up and installed a full Xcode 9 alongside Xcode 10 and then used `xcode-select` successfully. – Paul Masri-Stone Feb 21 '19 at 14:44
3

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.

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. Note that sudo xcode-select -s /Library/Developer would not work for me, just like the problem that @PaulMasri-Stone had.

Otherwise, you will want to follow the instructions that @Ilirium specified, but you only need to copy/rename the CommandLineTools directory.

bliptrip
  • 51
  • 2
0

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:

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