Anthony McLin

Updating XCode and MacPorts for OSX Lion


So, you've upgraded from Snow Leopard to Lion, and you're ready to jump back into development. Watch out! MacPorts and XCode need to be updated! Apple doesn't include XCode in the system updates, so you have to do it manually. If you installed XCode on Snow Leopard, you're probably running XCode 3 (unless of course you bought XCode 4). The latest that ships for Lion is 4.1 and is free. Here's how to upgrade your development environment:

Step 1: Install XCode 4.1

From the App store, find and download XCode. This will put an installer in your Applications folder. Run the installer. As of right now, there isn't an alternative download method from Apple. If you don't want to deal with the App store, you'll probably have to hit the warez sites.

Step 2: Uninstall XCode 3

Installing the new XCode doesn't replace your old one, it just moves it to a backup directory. Fire up your terminal:

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

Remove the leftover XCode folder:

sudo rm -rf /Developer-old

At this point I needed to run the XCode 4.1 installer again because the XCode 3 uninstall removed some of the shared command line utilities.

Step 3: Remove installed ports

Make a list of your installed ports in your home folder:

port -qv installed > ~/myports.txt

Uninstall all ports

sudo port -f uninstall --follow-dependents installed

Remove any partially installed ports and archives

sudo port clean --work --archive all

Step 4: Update MacPorts

MacPorts recommends that you reinstall the base package, but as of right now there isn't a Lion-specific installer. You should download and run the Snow Leopard installer again though.

After that, make sure you're updated and rsynched with the MacPorts server:

sudo port -v selfupdate
sudo port upgrade obsolete

Step 5: Reinstall the ports you need

Read through the text file we created, and reinstall only the ports you need. Don't worry about all the dependencies, they'll be added as necessary. Make sure that if you used specific variants (the package name is followed with a +) that you install those variants. For example, I didn't install git-core, I installed git-core +svn, so I need to now run:

sudo port install git-core +svn

Yes, even though Git and SVN are both included in XCode 4.1, I am reinstalling git. The build of Git that Apple included is quite limited, and I needed a specific extension git-svn so that I can migrate my projects from SVN to Git.

That should be it! Enjoy developing on OSX Lion!



MacPorts has a version 2.0.0 installer for Lion now:

If you don't install the updated MacPorts package for OS X Lion, you'll likely receive errors when you try to uninstall all ports. I had to install the updated MacPorts from the downloaded DMG file before the uninstall would work.

WARNING: I don't think the above post gives the right advice. If you look at the uninstall-devtools script, or run it with the arguments --verbose and --do-nothing, you will see it removes files that are not specific to xcode 4, such as /usr/bin/make.

The About.pdf that comes with XCode 4 implies that running the uninstaller script with --mode=all will remove all files, and since 4 replaces some files instead of moves them, running --mode=all with the xcode 3 uninstaller script will remove files for 4.

So you really check want to delete either the /Developer-old or /Developer-3.2.6 folder by dragging it to the trash, else you will have to reinstall XCode 4 and possibly redownload the 2GB installer!

- Rob (not verified)

- Anthony McLin

Hi - I have XCode 3 and 4 installed on 10.6. Can't I upgrade to Lion with XCode 3 in place? (i.e., don't remove it)

Also, is there an automatic way to reinstall all the Macport ports from the 10.6 install form the txt file you created? Like a bash script or something?

- john jameson (not verified)

Add new comment