Home > Casper, Mac administration, Mac OS X, Packaging, Scripting, Xcode > Building a Grand Unified Xcode 4.3 installer

Building a Grand Unified Xcode 4.3 installer

Apple has released Xcode 4.3 through the Mac App Store for all Macs running 10.7.3 and higher. In a break from the “installing an installer” method that Apple used for Xcode 4.1 and 4.2, the App Store is now installing Xcode as a self-contained application. This application, on first launch, then installs the other Xcode tools. The command line tools can be installed separately through the Xcode preferences, in the Downloads section.

For my users who are developers, I wanted to include Xcode 4.3 in their new machine builds and also install the command line tools automatically. To do this, I used a modified form of the methodology referenced in this post to repackage Xcode 4.3 for distribution without needing an Apple ID. See below the jump for the procedure.

Building the package

Install Xcode 4.3 from the Mac App Store onto your build machine.

Download the latest Command Line Tools for Xcode disk image from the Apple Developer site

Verify that the permissions on the Xcode application in /Applications are correct by running the following command:

sudo chown -R root:wheel /Applications/Xcode.app

Screen shot 2012-02-16 at 12.17.06 PM

Set up a new Iceberg project. Since we’ll need to run this installer with root privileges, I recommend setting the project type to Darwin: Package. That will open the project with the installation privileges automatically set to root.

Screen shot 2012-02-16 at 12.18.02 PM

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

Screen shot 2012-02-16 at 12.18.17 PM

In the Files section, click on the Applications folder in the listing.

Screen Shot 2012-02-17 at 1.27.43 PM

Go to the Archive menu and select Add Files…

Screen shot 2012-02-16 at 2.24.34 PM

Select the Xcode application in /Applications

Screen Shot 2012-02-16 at 2.36.44 PM

Verify that it’s now showing up under Applications in your Iceberg project

Screen shot 2012-02-16 at 12.29.20 PM

Select the Command Line Tools for Xcode disk image and drag it into the Additional Resources section of your Iceberg project.

Screen Shot 2012-02-17 at 4.39.52 PM

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

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



# Remove existing /Applications/Xcode.app from machine

if [ -d /Applications/Xcode.app ]; then
sudo rm -rf /Applications/Xcode.app


To install the command line tools, I’m using the following postflight script:



# Create /tmp/Command\ Line\ Tools mountpoint in /tmp

/bin/mkdir /tmp/Command\ Line\ Tools

# Mount the command_line_tools_for_xcode_.dmg disk image as /tmp/Command\ Line\ Tools

/usr/bin/hdiutil attach "$1/Contents/Resources/command_line_tools_for_xcode.dmg" -mountpoint /tmp/Command\ Line\ Tools -nobrowse -noverify -noautoopen

# Install the Xcode command line tools

/usr/sbin/installer -dumplog -verbose -pkg "/tmp/Command Line Tools/Command Line Tools.mpkg" -target /

# Clean-up

# Unmount the command_line_tools_for_xcode_.dmg disk image from /tmp/Command\ Line\ Tools
/usr/bin/hdiutil eject /tmp/Command\ Line\ Tools

# Remove /tmp/Command\ Line\ Tools from /tmp

/bin/rm -rf /tmp/Command\ Line\ Tools


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

sudo chmod a+x /path/to/preflight

sudo chmod a+x /path/to/postflight

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

Once the package has been built, test it by taking it to a test machine running 10.7.3 or higher that doesn’t have Xcode 4.3 and install it. The end result should be that Xcode 4.3 installs along with the command line tools without requiring an Apple ID.


I’ve tested this package both with a DeployStudio postponed install and as a Casper Self Service policy. In both cases, it worked well. Xcode installed properly and the command line tools showed up as installed.

For those who want to replicate this in Casper, there’s an additional script I’ve written named xcode_uninstall.sh which is used to uninstall prior Xcode installations before installing Xcode 4.3



# Uninstalls versions of Xcode prior to Xcode 4.3

sudo /Developer/Library/uninstall-devtools --mode=all


This script is set to run before the Xcode 4.3 installation. To make sure my users are aware that previous Xcode installs are removed, I’ve added this note.

Screen Shot 2012-02-17 at 4.08.39 PM

My Self Service policy is set up as shown in the screenshots below.

Screen shot 2012-02-17 at 4.19.34 PM

Screen shot 2012-02-17 at 4.19.52 PM

Screen shot 2012-02-17 at 4.19.58 PM

Screen shot 2012-02-17 at 4.20.02 PM

Screen shot 2012-02-17 at 4.20.13 PM

Screen shot 2012-02-17 at 4.20.22 PM

  1. slk00
    March 9, 2012 at 4:22 am

    /usr/bin/hdiutil attach “$1/Contents/Resources/command_line_tools_for_xcode_.dmg

    should be;
    /usr/bin/hdiutil attach “$1/Contents/Resources/command_line_tools_for_xcode.dmg

    • March 9, 2012 at 3:30 pm

      Thanks for the catch! It looks like Apple released a new version of the Command Line Tools for Xcode. The February 2012 version used the file name of “command_line_tools_for_xcode_.dmg” while the March 2012 version uses “command_line_tools_for_xcode.dmg”.

      I’ve updated the post to use the March filename, as hopefully Apple sticks with that one.

  2. slk00
    March 10, 2012 at 1:36 am

    If you can include the Installing of the Mobile Device Package, uninstall devtools etc.. in the scripts would be good as posted in here;

  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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: