Home > Mac administration, Mac OS X, Scripting, Xcode > Installing the Xcode command line tools on 10.7.x and later

Installing the Xcode command line tools on 10.7.x and later

A number of Mac admins need to provide the Xcode Command Line Tools for the Macs in their environments, either as part of building machines or afterwards. To help with this task, I’ve developed a script that will download and install the Xcode Command Line Tools on Macs running 10.7.x and higher. See below the jump for more details.

The script will perform different tasks, depending on which version of OS X it’s being run on.

On OS X 10.9.x and 10.10.x:

  1. Creates a placeholder file in /tmp. This file’s existence is checked by the softwareupdate tool before allowing the installation of the Xcode command line tools.
  2. Runs the softwareupdate tool and checks for the latest version of the Xcode command line tools for the OS in question.
  3. Uses the softwareupdate tool to install the latest version of the Xcode command line tools for the OS in question.
  4. Removes the placeholder file stored in /tmp.

On Mac OS X 10.7.x and 10.8.x:

  1. Uses curl to download a disk image containing the specified Xcode Command Line Tools installer from Apple’s web site.
  2. Renames the downloaded disk image to cltools.dmg.
  3. Mounts the disk image silently in /tmp. Disk image will not be visible to any logged-in user.
  4. Installs the Xcode Command Line Tools using the installer package stored on the disk image
  5. After installation, unmounts the disk image and removes it from the Mac in question.

Note: This script should not be used as part of a payload-free installer package. On 10.9.x and 10.10.x, the softwareupdate tool will not work properly when called from within an installer package.

The script is available below. It’s also available from my Github repo from the following link:


  1. February 3, 2015 at 3:46 pm

    Reblogged this on SutoCom Solutions.

  2. February 4, 2015 at 2:27 pm

    Reblogged this on /home/kOoLiNuS and commented:
    As always a great post on Der Flounder. Check it out!

  3. Brad Vrooman
    February 4, 2015 at 2:45 pm

    Great script! Thanks for writing this.

    I did notice a small error on line 27 – the cmd_line_tools_temp_file variable is missing its $, so the temp file doesn’t get deleted. It took me a few minutes to figure out why my test machines kept reporting software updates over and over during recon.

  4. February 24, 2015 at 4:30 am

    There’s no need to download the disk image, everything hosted at http://devimages.apple.com is seekable.

    hdiutil attach $DMGURL -mountpoint “$TMPMOUNT” -nobrowse

  5. niko
    July 19, 2016 at 11:04 pm

    I am newbie and sorry but lost in translation >.. i mean where and how i have access the to this command line tools now
    i spent all night on this
    if you pleeeeaaaase can help me it will be great .
    Some proms also when terminal ask me root accesss this was solved it seems
    again ur help would be greatly appreciated
    thanks a lot

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: