If you are on macOS Catalina and want to do this via the commandline/terminal, or the above solutions haven't worked, try these steps:
- Disable
SIP
(this needs to be done via recovery mode)
- Create a
soft simlink
linking your "Developer" directory (which contains the CommandLineTools directory/instance brew
is searching for) by running: sudo ln -s /path/to/Developer /path/to/Xcode.app/Contents
- Run the simlinker built into
brew
, to let brew
know where the CommandLineTools instance is (brew
was written by default to support both instances running in the same directory and has refused to update for logical reasons their docs explain), by running: sudo xcode-select --switch /path/to/new/simlinked/directory/for/CommandLineTools
Here's an example on my system:
- Xcode was originally located in:
/Applications/Xcode.app
- Developer directory, containing CommandLineTools was:
/Library/Developer
- ran:
sudo ln -s /Library/Developer /Applications/Xcode.app/Contents/
- ran:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/CommandLineTools
- refreshed shell (or open a new instance), and then ran:
brew doctor
, receiving the message: Your system is ready to brew.
For any of my new clients, I will often create these two aliases for their systems:
alias xbandaid="sudo xcode-select --reset" #when permissions might be lacking
alias xfix="sudo ln -s /Library/Developer /Applications/Xcode.app/Contents/ && sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/CommandLineTools" #for the fix as described above
I place these aliases in their bash/zsh profile, which on Catalina is typically either .zshrc
or .zprofile
if they use ZSH
, and .bashrc
or .bash_profile
if they use BASH
.
Disclaimer: Though I have tried this and it has successfully worked on "BigSur" client machines, I am not promising this will work for you on those installations. The same goes for MacPorts
and pkgsrc
also known as pkgin
put out by the Joyent Software/NetBSD Samsung Group
folks. They all worked for my clients and me, but reader discretion is advised.