Monday, August 13, 2012

MacPorts trouble with OS X Lion


It's a llama and an ass.


Recently I had trouble using MacPorts on Lion, for whatever reason. But I managed to find the fix, and here they are.
  1. Unable to do selfupdate:


    ~$ sudo port selfupdate
    ---> Updating MacPorts base sources using rsync
    MacPorts base version 2.0.4 installed,
    MacPorts base version 2.1.2 downloaded.
    ---> Updating the ports tree
    ---> MacPorts base is outdated, installing new version 2.1.2
    Installing new MacPorts release in /opt/local as root:admin; permissions 0755; Tcl-Package in /Library/Tcl

    Error: /opt/local/bin/port: port selfupdate failed: Error installing new MacPorts base: shell command failed (see log for details)

    Cause: ??? (shame on me for not checking the logs)
    Solution: Re-install Xcode (ref: MacPorts ticket #30507).
    Before re-installing Xcode, I had to uninstall my existing one. All I did was:
    1. Search for the Xcode executable from Spotlight
    2. Open the folder where the Xcode executable is (usually under /Applications).
    3. Drag the icon to the Trash bin. OR drag the Launcher icon to the Trash bin (this will prompt for are-you-sure-you-want-to-uninstall? confirmation). Click Yes/OK if asked.
    Unfortunately, I wasn't 100% sure my method of uninstalling Xcode is correct. So here's a most-likely-more-proper-way reference from StackOverflow: #6777462 - Can't Reinstall Xcode
    If you're able to successfully re-install XCode (mine was 4.4.1 as of this writing), you should be able to run ~$ sudo port selfupdate successfully.

    p.s. Actually, I also installed MacPorts 2.1.2 manually (go to MacPorts website, download the .dmg, install, etc.). So now I'm not entirely sure which fixed it.
  2. Unable to install Octave


    ~$ sudo port install octave
    Warning: The Command Line Tools for Xcode don't appear to be installed; most ports will likely fail to build.
    Warning: See http://guide.macports.org/chunked/installing.xcode.html for more information.
    Error: Unable to open port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?
    Error: Unable to execute port: upgrade perl5 failed

    Cause: (the error message was pretty explanatory on this one) "The Command Line Tools for Xcode don't appear to be installed" and (hence) "Failed to locate 'make' in path".
    Solution: Install the XCode Command Line Tool.
    1. Launch XCode.
    2. In XCode, go to: Preferences > Downloads
    3. Click "Install" for the "Command Line Tools" item (the screenshot shows that it's already installed).


    Currently I'm still unable to install octave because MacPorts failed to install gnuplot, but it's not the error above - so that's an improvement. It may be missing some dependencies...

    p.s. Prior to installing the Command Line Tools, I ran across this post: "GCC non-existent in Lion". So I also did what was recommended there: made a symbolic link to llvm-gcc-4.2 to /usr/bin/gcc. But the location of the newest Xcode directory in my system is a little different:

    ~$ sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 /usr/bin/gcc