Our DNA is written in Swift

You Don’t Need The Xcode “Command Line Tools”

When Apple made Xcode into its own app bundle it greatly simplified our lives as developers. This enabled incremental updates for the stable version can get from the app store. Also you get updates the same way as updates for other apps.

To cut down on file size Apple made several items optional downloads, like the documentation, older versions of Simulator or Command Line Tools. The latter you need if you are building stuff outside of Xcode, like Open Source projects. You know, bare knuckles, command line geekery.

However those tools are not needed if you want to say use svn or git. This article explains why.

When you download and install the “Command Line Tools” they integrate with your Unix file system structure the same way a compiler and header files would. The installer copies these files all over the place. All these tools (and many additional ones) are already included in as they are remote-controlled from Xcode when you build apps. Now if you update via the app store then the copies of these tools remain their current versions.

Have you ever read the description on the download window?

Even even tells you here, “Before installing, note …” that you don’t need this. It mentions two commands that will help us to live without it.

But! I want my GIT!

… and you shall have it. As I mentioned above the git tool (and svn too) are contained inside the bundle from where they are used by Xcode whenever you interact with repositories. There are two commands that you need to know to get to that.

You can have multiple Xcodes installed at the same time, the xcode-select command lets you inquire and set which Xcode is the one you want to use.

xcode-select --print-path

In this instance my system already has the Xcode 4.5 DP2 set as the current on. To select a specific Xcode you use the –switch switch.

sudo xcode-select --switch /Applications/

Note that you are required to use sudo (and enter your admin password) with this. You specify the path to the .app bundle. The tool appends the Contents/Developer. You can also specify the full path yourself, but why type more than necessary?

Having selected the correct Xcode for our purposes (which most of the time will the the normal stable in Applications) we can now run all the contained tools by means of xcrun. Let’s try git.

xcrun git --version
git version (Apple Git-33)
git --version
git version

Oh how nice, the git version contained in Xcode is much newer than the one I had manually installed in /usr/local/bin. This nicely illustrates the big advantage of using the bundled tools over those “installed eons ago”.

Waqar Malik has this Pro Tip for us:

This awesome little statement sets up an alias for your shell. Whenever you begin a command line with git the shell knows to substitute xcrun git for it. To make this definition persist you have to add it to your .profile (or create a new one if you don’t have one yet) or .bashrc file in your home folder. Either one is fine as long as this gets executed when you launch a new shell.

In case you are curious which actual path xcrun would use for a specific tool, there is the –find switch to “inquire within”

xcrun --find svn

Armed with the above knowledge you can save the 115 MB that the Command Line Tools need. This package serves a very distinct purpose and it is great for the home-brew-crowd that Apple is making it available as well as is supporting it.

Removing Already Installed Tools

There is no simple way to get rid of the installed files as they are copied all over the place. But there is a manifest file which lists all folders and files that are installed by the package. This allows us to go all “brute force” on the tools and remove them.

if [ ! -f "$RECEIPT_FILE" ]
  echo "Command Line Tools not installed."
  exit 1
echo "Command Line Tools installed, removing ..."
# Need to be at root
cd /
# Remove files and dirs mentioned in the "Bill of Materials" (BOM)
lsbom -fls $RECEIPT_FILE | sudo xargs -I{} rm -r "{}"
# remove the receipt
# remove the plist
echo "Done! Please restart XCode to have Command Line Tools appear as uninstalled."

Use at your own risk, it might remove more than you bargained for. So make sure you made a time machine backup before running this.

There is a second copy of the CLI Tools still present on your system even if you remove them with the above script. Xcode downloads end up in ~/Library/Caches/ and there are another 112168 KBytes to be reclaimed by removing the DMG file that you find in there, at the time of this writing named Xcode.CLTools.10.8-1.7.dmg.


For the rest of us who live and breathe inside Xcode, who only go to the command line to work efficiently with git and svn, we don’t need to install it. By creating aliases for the tools we need in our daily business we reap the benefits of current bundled versions and auto-updating of those through the app store.

By removing the installed CLI tools as well as deleting the downloaded DMG file you can reclaim over 200 MB of valuable disk space without any drawback.

Categories: Recipes


  1. Thanks for the script. A couple things:

    1) because “/usr/share/git-gui/lib/Git…” contains a space, xargs treats it as two separate arguments and tries to remove stuff like:


    This can be fixed by changing xargs to put quotes around the arguments, like this: … | xargs -I{} rm -r “{}”

    For users that have already run the script, they can run:

    sudo rm “/usr/share/git-gui/lib/Git” \
    “usr/share/git-gui/lib/Git” \
    “/usr/share/git-gui/lib/Git” \
    “/usr/share/git-gui/lib/Git” \
    “/usr/share/git-gui/lib/Git” \

    to clean up.

    2) The “Downloads” pane of Xcode’s Preferences still shows the Command Lines Tools are “Installed”, so Xcode is keying off something else to determine if they are installed. Any idea what?

  2. 1) thanks for carching that
    2) restart your xcode. For me it first shows as installed, but upon restart it disappeared.

  3. Thanks for the article. xcode-select was entirely new to me.

    Wrapping the commands you need in xcrun is an option, but it means you have to alias every command you want to use. Another option is to include the Developer bin directory in your PATH. This way you have instant access to all the commands. All you need to do is add the following to ~/.bash_profile

    export PATH

    If you edit the file in your current session, to use it you’ll need to reload the profile (“. ~/.bash_profile). Or you can simply close and reopen the window which does this for you.

  4. Thanks for excellent advice on removing!

    But after removing all the “Downloads” pane of Xcode’s Preferences shows the Command Lines Tools as “Installed”.

    I’ve tried to restart xcode, tried to clean xcode preferences, cleaned caches, even rebuild spotlight index. Last of all I removed Xcode 4.4 and installed again from AppStore, nothing helps.

    I’ve tried to figure with “find” what files has also been changed on my mac after command line tools were installed, but found nothing suspiciuous.

    Do you have any suggestions how to fix this?


  5. I found answer to my question :).

    The solution is simple.

    When you install “Command line tools”, four bom packages are installed, not just one:

    Removal procedure for all packages is the same: lsbom -lsf| …. rm

    After that Xcode shows that Command line tools are not installed.

    P.S. Happy SysAdmin day 🙂

  6. The whole thing works. The only difference is that the ‘’ package was called ‘’ on my environment.

  7. For those who don’t want to use command line tools but still want to compile some open source projects might
    find this little script useful. Just source it in your terminal before running make/configure like this:
    $ .
    or add to your .bashrc/.bash_profile. After that you should be able to compile most of the projects right away.
    ================== ====================
    OSX_VERSION=$(sw_vers | grep ‘ProductVersion’ | awk ‘{print $2}’)
    XCODE=$(xcode-select -print-path)

    export SDKROOT=$XCODE/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$OSX.sdk
    export PATH=$PATH:$XCODE/usr/bin

    export CFLAGS=”-isysroot $SDKROOT”
    export CXXFLAGS=”$CFLAGS”
    export CPPFLAGS=”$CFLAGS”
    export LDFLAGS=”-Wl,-syslibroot,$SDKROOT”

    export CC=gcc
    export CPP=”gcc -E”
    export CXX=g++

  8. Thanks for the script to remove the CLI tools. It worked like a charm!

  9. Thanks so much for this post. I decided to add the Xcode directory to my path, but I wanted to make it work with the xcode-select setting. Here is what I put into my profile script:

    XCRUN=$(which xcrun)
    if [ -f “$XCRUN” ]
    XCODEPATH=$(xcode-select –print-path)
    export PATH

    Now if only Apple would upgrade the git included with Xcode to git 1.8 :-).

  10. Thank you for posting the shell script.

  11. Has anyone else noticed that xcode-select is now just a link to xcrun, and therefore doesn’t do any of this nice stuff anymore? Or is it just on my install somehow?

  12. Thanks. This saved me a lot of headaches. Note however that htis doesn’t remove empty directories that were created by the installer. For instance, the installer put loads of .h header files inside a “Headers” subfolder of lots of Frameworks. Those Headers folders will not be removed, as an example. But it’s no big deal. Let’s not be pedantic.

  13. More info:

    Xcode from the Mac App Store installs 1 receipt per version/upgrade you perform:

    But if you do:

    lsbom -lfls | grep -v “^\.\/Appli”

    You can verify that NOTHING was installed OUTSIDE /Applications/

    So, to remove Xcode command line utilities:

    * Go to
    * Change the “rm -r” (recursive, risky and stupid) to just plain “rm” so that it doesn’t try to recursively remove directories. There’s no benefit to recursive removal since the receipt entries don’t list folders as the final item in the paths, so the folders won’t get removed anyway.

    To remove Xcode from MAS:

    * Just drag it to the trash.
    * Remove /var/db/receipts/* to get rid of all the receipts.

    My system is now clean!

  14. Oh and on modern installations, the Command Line Tools only installs these two packages:

    But the script I linked to doesn’t hurt, because if it doesn’t find those alternative receipts, it won’t try to remove them.

  15. Looking at the modification timestmaps of /var/db/receipts, I found one FINAL package that Xcode installed:

    It contains just the “rpmuxd” which is a daemon for remote debugging of mobile devices.

    To remove it:

    launchctl unload /System/Library/LaunchDaemons/
    cd /
    lsbom -fls /var/db/receipts/ | sudo xargs -I{} rm “{}”
    rm /var/db/receipts/*

    That’s it. Finally my system is free of Xcode and all traces!

  16. Thanks again for doing the initial groundwork and writing the guide that got me started! Hope my followup comments help someone else.

  17. Well, it’s an hour later and I think I might as well contribute my code here…

    I wrote a small tool that removes all orphaned folders.


    First, build the necessary text files that describe all files that were installed by the packages.

    mkdir /tmp/xcoderemove
    lsbom -fls /var/db/receipts/ > /tmp/xcoderemove/DevSDK.txt
    lsbom -fls /var/db/receipts/ > /tmp/xcoderemove/
    lsbom -fls /var/db/receipts/ > /tmp/xcoderemove/MobileDeviceDevelopment.txt

    Then, uninstall the files from each of the 3 packages above, using the method in the original blog post.


    Download my PHP code and save it as /tmp/xcoderemove/delete.php.

    Code is at:

    Run it with:

    php /tmp/xcoderemove/delete.php

    What it does: The code is very ugly because I didn’t give a damn about making it nice. I just wanted to get this done as fast as possible. But I guarantee that it doesn’t make mistakes. Anyway, it analyzes every path component and detects orphaned folders (even if they contain inadvertent .DS_Store files). It then removes those folders. It iterates over itself several times, until there’s nothing left to remove. So let it run for a while.

    It will remove hundreds of folders after an Xcode command line tools uninstallation.

    That is why I wrote the tool…

    Thanks for the initial article. My tool should only be run AFTER having removed the actual FILES using the method in this blog post.

    My tool is very safe to use because it ONLY removes ORPHAN (empty) folders. Never folders with content inside!

  18. To people that have already deleted their .bom package receipt files but want to run my tool:

    I suggest you re-install the command line utilities and build a deletion list and then delete it all again.

  19. I just discovered this GUI utility which I used to remove the Xcode 5 command line tools: It worked very well for me.