The macOS Command Line Tools were a welcome change for macOS users that previously had to install the entire Xcode application just to be able to compile software on their machine. The problem is that sometimes after a major OS version upgrade, things don’t work so well.
In particular, package managers for various languages will start failing because they are unable to compile software as part of installing or upgrading third-party dependencies.
xcode-select --install is sometimes not enough
To be honest, I don’t know why this is. It should be, but the crux of the matter, is that running
xcode-select --install is meant to fix these compilation issues, but often, it doesn’t, as it will tell you it already exists, and the OS doesn’t know what to do beyond that.
What prompted me to write this post, is after a recent macOS upgrade, I was getting errors trying to install a Node.js package that used Node-gyp. For those of you who don’t know what Node-gyp is:
node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js
Basically, Node-gyp is used when code needs to be compiled specifically for your platform as part of installing a Node.js package, and equivalent tools exist for Python, Ruby, and other popular languages.
The (supposed fix)
I say “supposed” because compiling software has a lot of moving parts so, but it worked for me and hopefully it works for you too!
After reading through countless threads with users having the same problem, I came across this “try turning it off and on again” style recommendation on GitHub from SimantorR.
So just open the terminal app, then run:
sudo rm -rf /Library/Developer/CommandLineTools
This will force macOS to re-download and install Commandline Tools from scratch. After this completed, I was able to install the Node.js dependencies without any errors.
I can’t guarantee this will fix every macOS related package install related issue, but it did fix it for me, and I hope it fixes it for you too.