You may wish to override the default Xcode Active Developer Directory so build tools can target a legacy version or non-default version of Xcode.
However, Managed server users may not change the default Xcode active developer directory (we use Xcode version 15.4 as an example here) using the "sudo xcode-select --switch /Applications/Xcode15.4.app" command due to lack of administrator access.
To override the default Xcode Active Developer Directory, simply set the environment variable "DEVELOPER_DIR" in the Terminal app to the desirable Xcode version.
Run a different version of Xcode
To properly utilize a different version of Xcode, you need to first set the proper DEVELOPER_DIR environment variable to the matching version, and then run the Xcode version in the Applications folder.
For example, the default Xcode ("Xcode.app") in the Applications folder could be version 16.0, and a different version of Xcode 15.4 (Xcode15.4.app) is available. To properly run "Xcode15.4.app", please do the following:
In the Terminal app, run command the following command:
export DEVELOPER_DIR=/Applications/Xcode15.4.app/Contents/Developer
Sequentially, run the next command noted below:
/Applications/Xcode15.4.app/Contents/MacOS/Xcode
The first line will properly set the DEVELOPER_DIR for Xcode 15.4, and the second line will run Xcode 15.4. For other versions of Xcode, simply replace the version number "15.4" with the desirable version you wish to run.
Change the environment variable
Temporarily set DEVELOPER_DIR to the available alternative Xcode version that is in the Applications folder. Or include the following in your bash profile ~/.bash_profile to overwrite default DEVELOPER_DIR to the desirable Xcode version:
export DEVELOPER_DIR=/Applications/Xcode15.4.app/Contents/Developer
Or, pass the variable directly to a build tool:
env DEVELOPER_DIR="/Applications/Xcode15.4.app" /usr/bin/xcodebuild
This will execute xcodebuild using an alternate developer directory (Xcode 15.4), rather than the xcodebuild tool that comes with the default Xcode.
Changing Command Line tools Globally
Please note that modifying tools or attempting to change the command line tools at the global level is not permitted on our Managed Server Plan.