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 & 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
7. MacPorts Project
7.1. Using Trac for Tickets
7.2. Contributing to MacPorts
7.3. Port Update Policies
7.4. Updating Documentation
7.5. MacPorts Membership
7.6. The PortMgr Team
8. MacPorts Guide Terms

MacPorts requires that some environment variables be set in the shell. When MacPorts is installed using the OS X package installer, a postflight script is run after installation that automatically adds or modifies a shell configuration file in your home directory, ensuring that it defines variables according to the rules described in the following section. Those installing MacPorts from source code must modify their environment manually using the rules as a guide.

Depending on your shell and which configuration files already exist, the installer may use .profile, .bash_login, .bash_profile, .tcshrc, or .cshrc.

The postflight script automatically sets the PATH variable, and optionally the MANPATH and DISPLAY variables according to the rules described below. If a current shell configuration file exists at installation time it is renamed to mpsaved_$timestamp. Those installing MacPorts from source code must modify their environment manually using the rules as a guide.

  • Required: PATH variable

    This variable is set by the postflight script to append the MacPorts executable paths to the default path as shown. The MacPorts paths are appended at the front of PATH so the MacPorts libraries will take precedence over vendor-supplied libraries for ported software at runtime.

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


    The user environment's $PATH is not in effect while ports are being installed, because the $PATH is scrubbed before ports are installed, and restored afterwards. To change the search path for locating system executables (rsync, tar, etc.) during port installation, see the macports.conf file variable binpath. But changing this variable is for advanced users only, and is not generally needed or recommended.

  • Optional: MANPATH variable

    Condition: If prior to MacPorts installation a MANPATH variable exists in a current .profile that contains neither the value ${prefix}/share/man, nor any empty values, the postflight script sets the MANPATH variable as shown below. Otherwise, the MANPATH variable is omitted.

    export MANPATH=/opt/local/share/man:$MANPATH

    Here are some examples of paths that contain empty values:

  • Optional: DISPLAY variable

    Condition: If installing on a Mac OS X version earlier than 10.5 (Leopard), and if a shell configuration file exists at time of MacPorts installation without a DISPLAY variable, the postflight script sets a DISPLAY variable as shown below. The DISPLAY variable is always omitted on Mac OS X 10.5 or higher.

    export DISPLAY=:0.0

To verify that the file containing the MacPorts variables is in effect, type env in the terminal to verify the current environment settings after the file has been created. Example output for env is shown below.


Changes to shell configuration files do not take effect until a new terminal session is opened.


You can set an environment variable in order to use your favorite text editor with edit option of port command.

MacPorts will check MP_EDITOR, VISUAL and EDITOR in this order, allowing you to either use a default editor shared with other programs (VISUAL and EDITOR) or a Macports' specific one (MP_EDITOR).

For example, to use the nano editor, add this line to your bash config:

export EDITOR=/usr/bin/nano

To use the user-friendly GUI editor TextWrangler (installation required), add this line:

export EDITOR=/usr/bin/edit

To keep a command-line text editor as default while using a graphic editor with portfiles, add this:

export EDITOR=/usr/bin/vi
export MP_EDITOR=/usr/bin/edit