Image for post
Image for post
Turn macOS Command Line Tools off and on again to fix compilation related problems after an OS upgrade

How to fix code compilation issues with Commandline Tools on macOS

TL;DR: Do not install Xcode, just do a fresh install of Command Line Tools

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

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.

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.

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.

Image for post
Image for post

So just open the terminal app, then run:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

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.

Written by

Helping teams make sense of the Cloud, Containers, Microservices and DevOps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store