Home > Mac administration, Mac OS X, Packaging, Scripting, Xcode > Building a Grand Unified Xcode 5.0.2 installer for Mavericks and Mountain Lion

Building a Grand Unified Xcode 5.0.2 installer for Mavericks and Mountain Lion

Apple has released Xcode 5.0.2 through the Mac App Store for all Macs running 10.8.4 and higher. While the command line tools for Mavericks are now included with Xcode, the command line tools for Mountain Lion can be installed separately through the Xcode preferences, in the Downloads section.

For my users who are developers, Xcode is part of their their new machine builds. I wanted to include Xcode 5.0.2 and also, where appropriate, install the command line tools automatically without needing to enter an Apple ID. With a little help from the Mac App Store, I was able to do this using Packages. See below the jump for the details.

I used the technique described here to capture a copy of the Xcode 5.0.2 installer from the App Store and then repackaged that installer with the Mountain Lion Xcode command line tools. Here’s the procedure I used.

Capture a copy of the Xcode 5.0.2 installer from the App Store

Screen Shot 2013-11-12 at 5.56.18 AM

Screen Shot 2013-11-12 at 6.20.16 AM

Download the latest Mountain Lion Command Line Tools for Xcode disk images from the Apple Developer site.

Set up a new Packages project and select Raw Package.

Screen Shot 2013-11-17 at 11.55.40 AM

In this case, I’m naming the project Xcode 5.0.2.

Screen Shot 2013-11-17 at 11.55.52 AM

Screen Shot 2013-11-17 at 11.58.01 AM

Click on the Settings tab and set the following:

In the Post-Installation Behavior section, set On Success: to Do Nothing
In the Options section, check the box for Require admin password for installation.

Screen Shot 2013-11-17 at 11.58.04 AM

Click on the Scripts tab in your Packages project.

Screen Shot 2013-11-17 at 12.05.06 PM

Select the following and drag them into the Additional Resources section of your Packages project:

Xcode 5.0.2 installer
Mountain Lion Command Line Tools for Xcode disk image

Screen Shot 2013-11-17 at 12.05.35 PM

The last pieces are removing any previous Xcode.app from /Applications and telling the Xcode installer and appropriate Command Line Tools for Xcode installer to run.

To remove any previous Xcode.app from /Applications, I’m using the following preinstall script:


# Remove existing copy of Xcode.app from /Applications

if [ -d "$3/Applications/Xcode.app" ]; then
   rm -rf "$3/Applications/Xcode.app"

To install Xcode and the command line tools, I’m using the following postinstall script:


# Determine OS version
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')

# Determine working directory

install_dir=`dirname $0`

# Install Xcode 5.0.2 using the specified installer package in the working directory

/usr/sbin/installer -dumplog -verbose -pkg $install_dir/"Xcode 5.0.2.pkg" -target "$3"

if [[ ${osvers} -eq 8 ]]; then

# Installing the Xcode 5.0.2 10.8 Command Line Tools

# Specify location of Xcode command-line tools disk image


# Specify a /tmp/commandlinetools.XXXX mountpoint for the disk image

  TMPMOUNT=`/usr/bin/mktemp -d /tmp/commandlinetools.XXXX`

# Mount the latest command line tools disk image to /tmp/commandlinetools.XXXX mountpoint

  hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" -nobrowse -noverify -noautoopen

# Install the Xcode command line tools by searching the top directory of the
# mounted disk image and installing any installer package found. Only the
# Command Line Tools installer will be found by this search so it will be
# installed without having the specify the current installer package's name

  /usr/sbin/installer -dumplog -verbose -pkg "$(/usr/bin/find $TMPMOUNT -maxdepth 1 \( -iname \*\.pkg -o -iname \*\.mpkg \))" -target "$3"

# Clean-up

# Unmount the command line tools disk image from /tmp/commandlinetools.XXXX

  /usr/bin/hdiutil detach "$TMPMOUNT"

# Remove the /tmp/commandlinetools.XXXX mountpoint

  /bin/rm -rf "$TMPMOUNT"


Once you’ve got the preinstall and postinstall script built, run the following commands to make the scripts executable:

sudo chmod a+x /path/to/preinstall

sudo chmod a+x /path/to/postinstall

Once completed, add the preinstall and postinstall scripts to your Packages project.

Screen Shot 2013-11-17 at 12.08.37 PM

Last step, go ahead and build the package. (If you don’t know to build, check the Help menu for the Packages User Guide. The information you need is in Chapter 3 – Creating a raw package project and Chapter 10 – Building a project.)


Once the package has been built, test it by taking it to a test machine running 10.8.x and a separate test machine running 10.9 that do not have Xcode 5.0.2 and install it. The end result should be that Xcode 5.0.2 installs along with the correct Xcode command line tools for the installed OS without requiring an Apple ID.

  1. November 18, 2013 at 2:50 pm
  2. David
    December 2, 2013 at 7:48 am

    Hi Rich,

    I followed your excellent guide but when a normal user runs Xcode for the first time it prompts:

    Install additional required components?
    Xcode 5 requires additional components to support running and debugging. Choose install to add required components.

    Clicking “Install”

    Then prompts for credentials. Do you have this experience? Any way to get around it?



    • Maik
      December 11, 2013 at 2:27 pm

      I have the same kind of issue. 10.8 seems to be fine so far. 10.9 is causing the problem that you need to agree to the license terms again… any idea?


  3. January 16, 2014 at 2:34 am

    Regarding the requirement to agree to the Xcode license per-machine, it would be worth having a look at /Library/Preferences/com.apple.dt.Xcode.plist 🙂

  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 )

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: