Getting Rid of Xcode Command Line Tools

Have you ever uninstalled Xcode Command Line Tools only to have it comes back again when Xcode gets updated or there’s a macOS update?  You might have a need for the command line tools at that time but don’t need it any longer — however it seems to find a way to get back into your system.

I experienced this not too long ago.  I installed Xcode’s command line tools because I needed an older version of Xcode for use with NVidia’s toolkit.  Then when I no longer have the need, I’ve uninstalled it as per Apple’s directions.  But strangely during the next macOS update cycle — which also updated Xcode in roughly the same time frame — I was prompted to update the command line tools as well.  What’s worse, there’s no way to opt out and I ended up installing the command line tools only to un-install it again. What an annoyance and waste of bandwidth.

Fortunately after much, much googling, I’ve discovered a way to permanently uninstall this command line tools.  I’ve also find a way to leverage the Xcode IDE for use by command line applications as well. Interested? Read on.

Real Mac Developer

Uninstalling Xcode Command Line Tools

To remove Xcode Command Line Tools (which is, by the way, different than the full Xcode IDE), you will need to go through two steps.

  1. Remove the files consisting the command line tools.
  2. Remove the receipts to prevent it from coming back again.

The first step is easy enough. It’s the second step that’s rather tricky because these receipt files are located in a read-only zone guarded by System Integrity Protection (SIP).

Removing Xcode Command Line Tools

As per Apple’s document TN2339, removing the command line tools is as simple as deleting a folder.

1
sudo rm -rf /Library/Developer/CommandLineTools

However in my personal experience, the command line tools would just get installed again the next time it gets updated. Thus you will need to follow the next step to fully remove the command-line tools.

Removing Receipt Files

Another set of files that you would need to remove are the receipt files of Xcode command line tools.  These files starts with the name com.apple.pkg.CLTools* and resides in the /System/Library/Receipts/ folder.  However since its location is inside one of SIP’s protected folders, removing them is quite involved.

What you need to do is to boot into macOS Recovery and then remove those receipt files from there. There’s really no need to disable SIP and put your system at risk just to remove these few files.  Booting from the Recovery OS also means that no other applications are running — which further reduce the risk of any malware modifying your crucial system files.

Follow these steps to remove those pesky command line tools receipt files.

  1. Restart your mac and hold ⌘R to boot into macOS Recovery.
  2. Go through the language selection and select your preferred language.
  3. In the Recovery Tool, open Disk Utility
  4. Select your mac’s internal drive (usually named “Macintosh HD” if you haven’t renamed it) and then click mount.
  5. You probably need to select an administrative user and enter that user’s password to unlock the drive.
  6. Having mounted the internal drive, close the Disk Utility app.
  7. The Recovery Tool should appear again.
  8. This time click Utility option in the menu bar and then Terminal
  9. The Terminal app should open.
  10. Using the Terminal, locate your mounted internal drive in the /Volumes folder and list its files. Again, the name is likely “Macintosh HD”
    1
    2
    cd "/Volumes/Macintosh HD"
    ls
  11. You should see a familiar macOS boot volume folder structure.
  12. Then go to the System/Library/Receipts folder
    1
    cd System/Library/Receipts
  13. Look for the command line tools receipts files.
    1
    ls -l com.apple.pkg.CLTools*
  14. If they are there, remove them
    1
    rm com.apple.pkg.CLTools*
  15. And that’s it. The command line tools shouldn’t return unless you explicitly downloaded and install them again.

Using the Full Xcode as Command-Line Tools

Really, the command line tools are meant for those who doesn’t need the full Xcode IDE.  Maybe they need it just for compiling open-source packages.  Perhaps they only do cross-platform Unix development and uses Emacs, VIM, or some other text editors to write code. For those people, the full Xcode is a monstrosity: gigabytes containing IDE and simulators for three operating systems (iOS, tvOS, watchOS) that they are not going to write software for.

But if you really use Xcode to develop Apple-specific software, then the reverse is true: the command-line tools duplicates of what the full Xcode IDE already provide and hence would waste precious space on your startup volume. However, some open-source package’s build systems seems to require the command line tools.  Is there a way to make them use the same compilers that Xcode IDE provide?

Yes there is. Read on.

The first step of business is to configure Xcode as the default compiler for the system.  This is even more important if you have more than one copy of Xcode installed (the other one would likely be a beta of a future version of Xcode). Follow these steps to configure Xcode in the command line.

  1. Open Xcode IDE
  2. In Xcode’s application menu, select the Preferences menu option.
  3. Activate the “Locations” tab
  4. In the “Command Line Tools” section, select the current version of Xcode as default (you might be asked to enter your password or restart iTunes if you haven’t done this before).
  5. Open Terminal
  6. Enter the following command and ensure that the output points to a location from within Xcode.app’s bundle:
    1
    xcrun —show-sdk-path

Now that you have setuo Xcode as the default compiler, you might want to setup a few environment variables to let open-source tools know about it.  Edit your terminal session’s startup script – usually ~/.bash_profile and add these environment settings in.

1
2
3
4
5
xcode_path=$(xcrun --show-sdk-path)
export CFLAGS="-I${xcode_path}/usr/include"
export CPPFLAGS="-I${xcode_path}/usr/include"
export LDFLAGS="-L${xcode_path}/usr/lib"
unset xcode_path

Those variables would sets the header files needed to build C and C++ applications. Furthermore it also lets linkers know where to find static libraries for these languages.

And that’s just about it.  You’ve just saved about 200 megabytes of space on your startup volume. Space that hopefully you can find better use.

Until next time.



Avoid App Review rules by distributing outside the Mac App Store!


Get my FREE cheat sheets to help you distribute real macOS applications directly to power users.

* indicates required

When you subscribe you’ll also get programming tips, business advices, and career rants from the trenches about twice a month. I respect your e-mail privacy.

Avoid Delays and Rejections when Submitting Your App to The Store!


Follow my FREE cheat sheets to design, develop, or even amend your app to deserve its virtual shelf space in the App Store.

* indicates required

When you subscribe you’ll also get programming tips, business advices, and career rants from the trenches about twice a month. I respect your e-mail privacy.

3 thoughts on “Getting Rid of Xcode Command Line Tools

  1. Hi Sasmito and thanks for your article. I’m running the latest version of Catalina (10.15.20 and want to get of the CLTools update warning, even after removing the command line tools subdir in /Developer.
    I noticed the cCLTools pkg files were stored in /library/apple/system/library/receipts. After starting in maintenance mode, I was unable to delete those files unfortunately. The files simply were not visible in maintenance mode. Do you have any other ideas on how to delete them? Any help would be much appreciated!

    Cheers,

    Wopke

    1. Try looking at the boot volume (as opposed to Catalina’s data volume) in “/System/Library/Receipts” from the recovery OS. Google for “Catalina firmlinks” to find out more on this.

Leave a Reply to WopkeCancel reply