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 .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 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
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.
MANPATH= TERM_PROGRAM=Apple_Terminal TERM=xterm-color SHELL=/bin/bash TERM_PROGRAM_VERSION=237 USER=joebob __CF_USER_TEXT_ENCODING=0x1FC:0:0 PATH=/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin PWD=/Users/joebob EDITOR=/usr/bin/pico SHLVL=1 HOME=/Users/joebob LOGNAME=joebob DISPLAY=:0.0 SECURITYSESSIONID=b0cea0 _=/usr/bin/env
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