Building Xcode Project in Terminal – Choosing another Xcode

2 Solutions Collect From Internet About “Building Xcode Project in Terminal – Choosing another Xcode”

I think the command xcode-select is here for this precise reason.

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).

  -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
  -v, --version               print the xcode-select version
  -r, --reset                 reset to the default command line tools path

I had the same problem. I had changed the command-line tools option in Xcode’s preferences. Here you can choose which version of Xcode, you wanted to use.
enter image description here