Using Xcode-select and bash aliases

04 Oct 2013

Here is how I have set up Xcode 4 and 5 on my Macs and how I switch between them.

In my Applications folder, my main Xcode is always the latest. This makes for easy updates and is where Apple expects to find Xcode.

In a sub folder of Applications called “Xcode 4” I have a copy of Xcode 4 that I downloaded from Apple’s download site [requires a login]

I use the xcode-select command line utility to switch between them.

The basic commands look like this:

To switch to Xcode 5 (my main Xcode)

sudo xcode-select --switch /Applications/Xcode.app

To switch to Xcode 4 (the Xcode in the sub-folder)

sudo xcode-select --switch /Applications/Xcode\ 4/Xcode.app

This is a lot of typing. So, I have made some aliases in my bash profile. They look like this.

alias xc5="xcode-select --switch /Applications/Xcode.app"

alias xc4="xcode-select --switch /Applications/Xcode\ 4/Xcode.app"

Now I should be able to just type sudo xc5 and sudo xc4 from the Terminal.app to switch back and forth. However, this will not work and throws an error. I also need to make an alias for sudo like this:

alias sudo="sudo "

Notice the extra space? That is the magic part. So, with these three aliases, I can jump to the command line and switch over to a different Xcode. Then when I open the version of Xcode I want to use, all of the build tools, etc will work correctly.