1. Introduction
2. Installing MacPorts
2.1. Install Xcode
2.2. Install MacPorts
2.3. MacPorts Upgrade
2.4. Uninstall
2.5. MacPorts and the Shell
3. Using MacPorts
3.1. The port Command
3.2. Port Variants
3.3. Common Tasks
3.4. Port Binaries
4. Portfile Development
4.1. Portfile Introduction
4.2. Creating a Portfile
4.3. Example Portfiles
4.4. Port Variants
4.5. Patch Files
4.6. Local Portfile Repositories
4.7. Portfile Best Practices
4.8. MacPorts' buildbot
5. Portfile Reference
5.1. Global Keywords
5.2. Global Variables
5.3. Port Phases
5.4. Dependencies
5.5. Variants
5.6. Tcl Extensions
5.7. StartupItems
5.8. Livecheck / Distcheck
5.9. PortGroups
6. MacPorts Internals
6.1. File Hierarchy
6.2. Configuration Files
6.3. Port Images
6.4. APIs and Libs
6.5. The MacPorts Registry
7. MacPorts Project
7.1. Using Trac for tickets
7.2. Contributing to MacPorts
7.3. Port Update Policies
7.4. MacPorts Membership
7.5. The PortMgr Team
8. MacPorts Guide Terms
Glossary

If you are using OS X, you should install MacPorts using the OS X package installer unless you do not wish to install it to /opt/local/, the default MacPorts location, or if you wish to install a pre-release version of MacPorts base. However, if you wish to install multiple copies of MacPorts or install MacPorts on another OS platform, you must install MacPorts from the source code.

Note

Though a distinction is made between pre-release and release versions of MacPorts base, the ports collection supports no such distinction or versioning. The selfupdate command installs the latest port revisions from Subversion (at a slight delay), and updates MacPorts base to the latest released version.

The OS X package installer automatically installs MacPorts, sets the shell environment, and runs a selfupdate operation to update the ports tree and MacPorts base with the latest release.

  1. Download the latest MacPorts-2.3.1-....pkg installer from the MacPorts download directory. Here are direct links for the latest versions of OS X:

    OS X 10.9 Mavericks:
    MacPorts-2.3.1-10.9-Mavericks.pkg
    OS X 10.8 Mountain Lion:
    MacPorts-2.3.1-10.8-MountainLion.pkg
    OS X 10.7 Lion:
    MacPorts-2.3.1-10.7-Lion.pkg
  2. Double-click the downloaded package installer to perform the default easy install.

  3. After this step you are done already, MacPorts is now installed and your shell environment was set up automatically by the installer. To confirm the installation is working as expected, now try using the port command in a new terminal window.

    $ port version
    Version: 2.3.1

    In case of problems such as command not found, make sure that you opened a new terminal window or consult Section 2.5, “MacPorts and the Shell”. Otherwise, please skip the remainder of this chapter and continue with Chapter 3, Using MacPorts in this guide.

If you installed MacPorts using the package installer, skip this section. To install MacPorts from the source code, follow the steps below.

  1. Download and extract the MacPorts 2.3.1 tarball. Either do so using your browser and the Finder, or use the given commands in a terminal window.

    $ curl -O https://distfiles.macports.org/MacPorts/MacPorts-2.3.1.tar.bz2
    $ tar xf MacPorts-2.3.1.tar.bz2
  2. Afterwards, perform the commands shown in the terminal window. If you wish to use a path other than /opt/local, follow the instructions for installing multiple copies of MacPorts instead.

    $ cd MacPorts-2.3.1/
    $ ./configure
    $ make
    $ sudo make install
  3. Please continue with Section 2.5, “MacPorts and the Shell” to set up your shell environment.

If you installed MacPorts using the package installer, skip this section.

There are times when some may want to run MacPorts from a version newer than the current stable release. Maybe there's a new feature that you'd like to use, or it fixes an issue you've encountered, or you just like to be on the cutting edge. These steps explain how to run completely from trunk, using only Subversion to keep MacPorts up to date.

  1. Check out MacPorts source

    Pick a location to store a working copy of the MacPorts code. For this example, /opt/mports will be used, but you can put the source anywhere. This example will create /opt/mports/trunk containing everything needed for MacPorts.

    $ mkdir -p /opt/mports
    $ cd /opt/mports
    $ svn checkout https://svn.macports.org/repository/macports/trunk

    Note

    You only really need the base subdirectory to run MacPorts, so you can avoid checking out the rest if you don't want to use a Subversion-based ports tree (see Step 3 below). To just get the base directory, append /base to the end of the svn checkout command above. The resulting directory will then be /opt/mports/base.

  2. Build and Install MacPorts

    MacPorts uses autoconf and makefiles for installation. These commands will build and install MacPorts to /opt/local. You can add the --prefix option to ./configure to relocate MacPorts to another directory if needed.

    $ cd /opt/mports/trunk/base
    $ ./configure --enable-readline
    $ make
    $ sudo make install
    $ make distclean
  3. (Optional) Configure MacPorts to use port information from Subversion

    This step is useful if you want to do port development. Open /opt/local/etc/macports/sources.conf in a text editor. The last line which should look like this:

    rsync://rsync.macports.org/release/tarballs/ports.tar [default]

    Change it to point to the working copy you checked out:

    file:///opt/mports/trunk/dports [default]

    Now MacPorts will look for portfiles in the working copy and use Subversion instead of rsync to update your ports tree.

  4. Environment

    You should setup your PATH and other environment options according to Section 2.5, “MacPorts and the Shell”.

Occasionally a MacPorts developer may wish to install more than one MacPorts instance on the same host. Only one copy of MacPorts may use the default prefix /opt/local, so for additional installations use the option --prefix as shown below. It's also recommended to change the applications dir using --with-applications-dir to avoid conflicts in /Applications/MacPorts.

Note

The first command temporarily removes the standard MacPorts binary paths because they must not be present while installing a second instance.

$ export PATH=/bin:/sbin:/usr/bin:/usr/sbin
$ MP_PREFIX=/opt/macports-test
$ ./configure --prefix=$MP_PREFIX --with-applications-dir=$MP_PREFIX/Applications
$ make
$ sudo make install

After installing the second instance you might need to add

startupitem_install no

to $MP_PREFIX/etc/macports/macports.conf to avoid conflicts in /Library/LaunchAgents.