xcrun: error: invalid active developer path, problem after zsh update for flutter

13,774

Solution 1

It looks like the Command Line tools path is not set. If you have XCode then to setup the path you need to:

  1. Open XCode
  2. Open Preferences (,)
  3. Go to Locations tab
  4. For “Command Line Tools” select the current version screenshot showing preference

Solution 2

The error messages seem to be about Xcode CLI tools? If so, try these commands to reset it:

xcode-select --install
sudo xcode-select -s /Library/Developer/CommandLineTools/

Solution 3

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:

  1. Disable SIP (this needs to be done via recovery mode)
  2. 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
  3. 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.

Share:
13,774
giannik28
Author by

giannik28

Updated on July 27, 2022

Comments

  • giannik28
    giannik28 almost 2 years

    I updated my shell to zsh and when I type flutter --version I get this:

    '''xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),   
    missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    Failed to find the latest git commit date: VersionCheckError: Command exited
    with code 1: git -c log.showSignature=false log -n 1 --pretty=format:%ad
    --date=iso
    Standard out: 
    Standard error: xcrun: error: invalid active developer path
    (/Library/Developer/CommandLineTools), missing xcrun at:
    /Library/Developer/CommandLineTools/usr/bin/xcrun
    
    Returning 1970-01-01 01:00:00.000 instead.
    Flutter 0.0.0-unknown • channel unknown • unknown source
    Framework • revision  () • 1970-01-01 01:00:00.000
    Engine • revision b8752bbfff
    Tools • Dart 2.10.2'''
    

    WHAT SHOULD I DO? I'm not an expert in these things XD.

    Kind regards,

  • newbie
    newbie over 2 years
    This worked for me :)
  • Jamie
    Jamie over 2 years
    Thank you! This is exactly what I needed.
  • Rakesh Verma
    Rakesh Verma over 2 years
    you saved my day :) thanks