17 February 2012

Yak Shaving to Install Git Via MacPorts on OS X Lion



Today I needed to set up a new MacBook Pro and as such one of the tasks was to install git on OS X Lion. Being that I am a fan of MacPorts, I decided to start there but I ran into some strange errors. Unfortunately I wound up doing a lot of yak shaving.

The last time I installed MacPorts fresh, it was on a previous MacBook Pro that had OS X Snow Leopard installed. I successfully installed MacPorts and then used the port utility to install git without issue. Later I then updated to OS X Lion and had no issues with git or Xcode.

So from previous experience, I knew that before I could install MacPorts I would need to install Xcode, so I downloaded and installed Xcode 4.3 from the App Store. Then I attempted to install MacPorts, but began seeing errors about not being able to find the make utility. Sure enough, it was not in /usr/bin. After some hunting, I ran across a document titled New Features in Xcode 4.3 which noted the following:
'The command-line tools are not bundled with Xcode 4.3 by default. Instead, they can be installed optionally using the Components tab of the Downloads preferences panel...'

So I installed the command-line tools from the Xcode preferences panel and then proceeded with the MacPorts installation. It completed successfully so I moved on to the actual installation of git using the following command:
$ sudo port install git-core +bash_completion +doc +svn
Unfortunately this wound up with an error stating:
Error: Failed to install zlib
Hunting around, I wound up finding a few things such as this MacPorts issue, only to discover that this issue was closed as invalid. So I hunted some more and found this question on Stack Overflow which had one hint but not everything to fix the situation. I also found some advice in a document about Migrating a MacPorts install to a new major OS version or CPU architecture.
  1. Install the Xcode command-line tools from the Xcode preferences panel
  2. Update the /opt/local/etc/macports/macports.conf file to change from 'developer_dir /Developer' to just 'developer_dir'
  3. Clean all ports using sudo port clean all (this took a while)
  4. Now run the following steps:


$ sudo ln -s / /Developer
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs
$ sudo xcode-select -switch /Applications/Xcode.app
$ sudo port install git-core +bash_completion +doc +svn

After stumbling upon and utilizing these steps, I completed my yak shaving session and finally got git installed successfully. This cost me a total of about two hours. Here's a great Ren and Stimpy video about yak shaving. Now I'm on to another weird problem with this new laptop, a couple of System Preferences are dimmed and I can't figure out why. Anybody know what may be causing this?

4 comments:

  1. Really dude, you need to get on the homebrew bandwagon.

    ReplyDelete
  2. It's Casper: http://www.jamfsoftware.com/products/casper-suite. I think you know the right remedy... :)

    BTW - +1 for MacPorts. Don't know why you had so many issues. I was able to install and go on 10.7 with no problems. I did have to manually remove git (as installed by Xcode) as I wanted to use a newer version that will stash untracked files.

    ReplyDelete
  3. I think your step 1 is wrong. It should be:
    ln -s / /Developer
    This way paths like /Developer/usr/bin/llvm-gcc-4.2 will work (which I ran into in macports py25-numpy); with your suggestion they will cause a symlink loop.

    ReplyDelete