MacPorts

From HerzbubeWiki
Jump to: navigation, search

This document contains information about MacPorts, a project that packages software so that it can be built on Mac OS X using the "Developer Tools" (or "Xcode Tools") environment provided by Apple.

MacPorts is an alternative to Fink because its packages often are more up-to-date than those of Fink. MacPorts and Fink can co-exist on the same system.


Documentation


Installation

Prerequisites

Because MacPorts compiles many things from source, Apple's developer tools should be installed before anything sensible can be done with MacPorts. This includes

  • Xcode
  • Apple's Command Line Developer Tools (can be installed from within Xcode, under Preferences > Downloads)


I also prefer to have an X11 installation on the system before starting with MacPorts. This can be either the version provided by Apple, or XQuartz. I usually have XQuartz so that I can run up-to-date versions of The Gimp.


Installation

Installation is simply done via a Mac OS X .pkg installer. Similar to Fink, MacPorts tries not to interfere with the rest of the system, and therefore installs into this path:

/opt/local

The installation process will update your shell environment (in my case ~/.profile) to modify the PATH environment variable like this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

After installation, you should therefore make sure that you open a new terminal session to get the updated environment. The first command that should then be issued is

sudo port -v selfupdate


Files and Folders

The actual packages (known as "Ports") are located under

/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports

The configuration file is this one

/opt/local/etc/macports/macports.conf


Usage

To update the installed packages

sudo port selfupdate         # updates the port descriptions
sudo port upgrade outdated   # upgrade installed ports

To list all ports known to MacPorts

port list

To list all installed ports

port installed
port list installed   # slower but with more details

To list all versions of a specific port (including older versions that are currently not active)

port installed foo

To find out which port installed a file (`dpkg -S` in Debian)

port provides /path/to/file

To see a description of a specific port

port info foo

To install a package (or "port")

sudo port install foo


Special instructions for installing certain packages

Git

Git by default is compiled without SVN support (i.e. the git-svn command is not available). Use this command to get SVN support:

sudo port install git-core +svn

(preceded by sudo port deactivate git-core if Git is already installed)


Troubleshooting

Getting and building an older revision of a port

If the older revision of the port has been built and installed before, you can simply reactivate it:

sudo port activate foo @1.2.3_0

Get rid of the currently installed version of the port:

sudo port uninstall foo

Check out which revision you need by inspecting a port's history in the Subversion repository

https://trac.macports.org/log/trunk/dports

On the command line, get the revision you need

svn checkout -r 123456 https://svn.macports.org/repository/macports/trunk/dports/path/to/port

Now install the port

cd foo   # the SVN working folder that you just checked out
sudo port install


Unable to execute port: could not read /path/to/port: permission denied

When trying to install a "local" port, i.e. one that is not in its normal path under /opt/local, I had the following error:

nargothrond:~/Desktop/libgphoto2-2.4.11 --> sudo port install
Error: Unable to execute port: could not read "/Users/admin/Desktop/libgphoto2-2.4.11/Portfile": permission denied

This is due to MacPorts running as non-privileged user during a port installation. The problem is probably not the missing permission on the file itself that is being reported, but missing permission on one of the parent folders. In the example above, I was able to fix the problem by moving the local port folder to /tmp.