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

2.5. MacPorts and the Shell

MacPorts requires that some environment variables be set in the shell. When MacPorts is installed using the macOS 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 .zprofile, .profile, .bash_login, .bash_profile, .tcshrc, or .cshrc.

2.5.1. The Postflight Script

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 prepend the MacPorts executable paths to the current path as shown. This puts the MacPorts paths at the front of PATH so that the MacPorts binaries will take precedence over vendor-supplied binaries.

    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 items separated by a colon, the postflight script sets the MANPATH variable as shown below. Otherwise, the MANPATH variable is omitted.

    export MANPATH=/opt/local/share/man:$MANPATH
  • 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

2.5.2. Verify the Configuration File

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.


2.5.3. Optional Editor Variables

You can set an environment variable in order to use your favorite text editor with the port edit 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 BBEdit (installation required), add this line:

export EDITOR=/Applications/BBEdit.app/Contents/Helpers/bbedit_tool

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

export EDITOR=/usr/bin/vi
export MP_EDITOR=/Applications/BBEdit.app/Contents/Helpers/bbedit_tool