1. Introduction
2. Installing MacPorts
2.1. Install Xcode
2.2. Install MacPorts
2.3. Upgrade MacPorts
2.4. Uninstall MacPorts
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 & Useful Tcl Commands
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
6.6. Tests
7. MacPorts Project
7.1. Using Trac for Tickets
7.2. Using Git and GitHub
7.3. Contributing to MacPorts
7.4. Port Update Policies
7.5. Updating Documentation
7.6. MacPorts Membership
7.7. The PortMgr Team
8. MacPorts Guide Glossary
Glossary

2.2. Install MacPorts

If you are using macOS, you should install MacPorts using the macOS 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.

2.2.1. macOS Package Install

The macOS 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.9.3-....pkg installer from the releases on GitHub. Here are direct links for the latest versions of macOS:

    macOS 14 Sonoma:

    MacPorts-2.9.3-14-Sonoma.pkg

    macOS 13 Ventura:

    MacPorts-2.9.3-13-Ventura.pkg

    macOS 12 Monterey:

    MacPorts-2.9.3-12-Monterey.pkg

    macOS 11 Big Sur:

    MacPorts-2.9.3-11-BigSur.pkg

    macOS 10.15 Catalina:

    MacPorts-2.9.3-10.15-Catalina.pkg

    macOS 10.14 Mojave:

    MacPorts-2.9.3-10.14-Mojave.pkg

    macOS 10.13 High Sierra:

    MacPorts-2.9.3-10.13-HighSierra.pkg

    macOS 10.12 Sierra:

    MacPorts-2.9.3-10.12-Sierra.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 port in a new terminal window.

    $ port version
    Version: 2.9.3

    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.

2.2.2. Source Install

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.9.3 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.9.3.tar.bz2
    $ tar xf MacPorts-2.9.3.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.9.3/
    $ ./configure
    $ make
    $ sudo make install
  3. Please continue with Section 2.5, “MacPorts and the Shell” to set up your shell environment.

2.2.3. Git Install

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 setup MacPorts for developers, using only Git to keep MacPorts up to date.

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 ports tree, and updates MacPorts base to the latest released version.

  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/macports-base containing everything needed for MacPorts.

    $ mkdir -p /opt/mports
    $ cd /opt/mports
    $ git clone https://github.com/macports/macports-base.git
    $ cd macports-base
    $ git checkout v2.9.3  # skip this if you want to use the development version
  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 --prefix to ./configure to relocate MacPorts to another directory if needed.

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

    This step is useful if you want to do port development. Check out the ports tree from git:

    $ cd /opt/mports
    $ git clone https://github.com/macports/macports-ports.git

    Then open /opt/local/etc/macports/sources.conf in a text editor. The last line should look like this:

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

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

    file:///opt/mports/macports-ports [default]

    Now MacPorts will look for portfiles in the working copy and use Git 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”.

2.2.4. Install Multiple MacPorts Copies

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. Use --without-startupitems to automatically set startupitem_install no in the new macports.conf, which is required to avoid conflicts in /Library/LaunchAgents or /Library/LaunchDaemons.

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 --without-startupitems
$ make
$ sudo make install