Much has been written about managing multiple versions of Xcode. With the release of the Mac App Store, Apple changed the Xcode install process. It’s time to revisit this discussion, including installation of older Xcode versions as well as some tips on managing beta releases.
Prior to the Mac App Store, it was quite simple to work with multiple versions of Xcode, as each release had an option to specify the destination folder during install. No more, installations (non-beta) will overwrite an installed version of an app with the latest release, as each new release is installed in the /Applications folder with the name Xcode.app.
In this post I’ll walk through how I prefer to manage multiple versions of Xcode. If you have another approach, please post a comment.
Installing Multiple Versions of Xcode
More than once, having a previous install of Xcode has saved my bacon, as installing the latest production release can introduce unexpected quirks in the build process. In the interest of progress this is all well and good, however, if you are on deadline, not so much.
One option would be to rename the current production version of Xcode to a new name, and proceed with the install of the latest release.
However, I prefer to use a separate folder for each version (more on this below). This is very straightforward – before installing the latest production release (and overwriting Xcode.app in the /Applications folder):
- Create a new folder with the relevant release number in the /Applications folder. For instance: /Applications/Xcode4.6
- Copy the current version of Xcode from /Applications into the folder above
- Install new production version (from Mac App Store), which will overwrite Xcode.app in /Applications
You will then have something similar to this:
Selecting the Version of XCode To Build With
I often use command line tools, typically a bash shell script, to build and sign iOS applications. I move between versions of Xcode using the command line tool xcode-select. For example, here is how to select Xcode 4.6 saved in a folder of the same name:
$sudo xcode-select --switch /Applications/Xcode4.6/Xcode.app
When using the –switch option you must run as root, hence the reference to sudo.
Once this is run, the command line tools xcrun and xcodebuild will use the relevant tools based on the select statement above. I often add the xcode-select statement into my shell scripts directly.
The primary reason I prefer to use a folder based approach versus giving each release a different name is that I can easily update a build script to accept a command line parameter. Here’s how a shell script may look that accepts one parameter to specify the Xcode version to build with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/bin/sh # We need to know which version to use if [ $# -ne 1 ] then echo "\nUsage: ./`basename $0` Version\n"Example: ./`basename $0` Xcode4.6\\n exit fi # Select Xcode version sudo xcode-select --switch /Applications/$1/Xcode.app/Contents/Developer echo 'Current Xcode build path:' xcode-select --print-path # Continue with the build process ...
To run the script, from the command line:
which will output:
Lines 4-8 simply verify that a parameter has been passed in when calling the script, showing a usage message if needed:
Usage: ./build.sh Version Example: ./build.sh Xcode4.6
Check Which Version of Xcode is Active
As a sanity check, when things just aren’t coming together, you can check which version of Xcode is being used for builds as follows:
Here is the output when the default version of Xcode is active (/Applications/Xcode.app):
~$ xcode-select --print-path /Applications/Xcode.app/Contents/Developer
Installing An Older Version of Xcode
Sometime over the past few months Apple changed the location for Downloads for Apple Developers. Here is where you can now search for and install an older Xcode version: http://developer.apple.com/downloads/.
Once downloaded, create a new folder for the Xcode release, you can do this either in Finder or via the command line:
~$ mkdir /Applications/Xcode5.0
Open the dmg file and you will see a dialog (without the red “X”):
Using Finder, drag/drop the Xcode.app icon into the folder created in the step above – not in the /Applications folder as the screenshot indicates.
That’s all there is to it, you can now start the app as needed or use xcode-select to point the build tools to this release.
Installing Multiple Xcode Beta Releases
When Apple releases a beta of Xcode they name the application with a relevant beta tag, for example Xcode51-Beta4.app. Thus, moving the release to the /Applications folder won’t overwrite anything.
Although the above works fine, I like a little more organization as I tend to keep more than one beta installed, in the event a new beta breaks something.
I install Xcode beta releases into a separate folder /Applications/XcodeBeta. A screenshot of my current XCode beta folder is shown below:
To install multiple Xcode beta releases, I use the same process as above, open the downloaded .dmg and drag/drop the Xcode app into the /XcodeBeta folder. If I install a new beta and things no longer work with an existing project, I can simply go back a version.
Once the production release for the beta cycle is available, and I’ve installed and verified my projects all work as expected, I delete the contents of /Applications/XcodeBeta until the next beta cycle begins.
Other recommendations, tips and tricks on managing multiple Xcode versions are welcome.