Mac OS
How to fix Errors
xcrun: error

xcrun: error: invalid active developer path: how to fix

Example xcrun error

Sometimes you'll get an error like the one above when typing command line commands in Mac OS. The fix is simple. What you need to know is why the error occurs, and if you're studying development, I recommend reading the cause section before moving on.

1. Workaround

Let's start with the workaround.

Type the following in your terminal and press Enter.

xcode-select --install

In the window that opens, click the Install button.

Developer Tools Installation Popup

Finally, click the OK button in the license window and the installation will proceed. After the installation is finished, type the same command and it will run without errors.

Run python3

2. Cause

Now that we've fixed the error, let's look at why it happens. Starting with the error itself, here's what it looks like.

$ python3
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

I typed the command python3, but the error message says there is no xcrun. Where did xcrun come from?

2.1. xcrun

manpagez explains it like this: (opens in a new tab) To give you an idea, what xcrun does is to run the version of Python that Xcode uses from among the many Pythons installed on my machine, or that comes with the CommandLineTools to run the version of Python installed on my machine. The version that xcrun runs is the one that Mac OS thinks is best for our operating system at the moment.

Of course, your thoughts trump the system's. So xcrun runs after it has explored all the PATHs. For those who don't know, it's worth explaining the relationship between CLI commands and the PATH.

2.2. CLI and PATH

Programs that run from the CLI, such as the Python interpreter, can exist anywhere on your computer. It could be in /opt/homebrew/bin/python3, or it could be in /usr/bin/python3. To run this program, we need to enter the top level directory starting with /.

/usr/bin/python cli

The PATH is what allows you to omit these prefixed directory addresses. If you specify the desired directory in the PATH, the computer will automatically find and run the python3 executable in that folder.

python3 cli

My computer's PATH can be found with the following command.

echo $PATH

You should see multiple paths output, as shown below.

echo $PATH

It will go to the beginning of the multiple PATHs it prints, and if the python3 executable exists, it will run it, and if it doesn't exist at the end, it will print a message saying it wasn't found.

To verify the message, let's run python4, which does not exist on the machine.

Screen when running python4

What xcrun does is find all the above PATHs and then execute them to find and run the python3 executable that is installed for the OS and Xcode.

2.3. Mac OS Update

CommandLineTools and Mac OS updates are closely related, since CommandLineTools itself, of which xcrun is a part, is a set of applications optimized for Mac OS. Sometimes Mac OS updates include updates for CommandLineTools. This creates a bug which causes Mac OS updates to confuse or even reset the directory settings for xcrun.

The workaround above works to reverse the corrupted paths or repair programs which were initialized with a clean installation of CommandLineTools. The workaround is simple, but it was fun to look up xcrun and learn more about how the Mac OS works.

copyright for Mac xcrun error

© 2023 All rights reserved.