Applies to OS X 10.6 (Snow Leopard) and newer; tested through MacOS 10.13 (High Sierra)
The general advice for adding particular directories to your PATH
environment variable on MacOS is to add an export PATH
to your ~/.bashrc
or equivalent. This has some drawbacks. For one, it only affects that shell for that user.
Additionally, sometimes installed Applications modify the system's default PATH
in ways that you don't want.
Understanding how MacOS generates the PATH
environment variable is instructive.
TL;DR read man path_helper
and be enlightened
- The system default paths are read, one per line from the file
/etc/paths
and added toPATH
- The files in
/etc/paths.d
are read, and the contents of each are added toPATH
; the order in which the files are read is not reliable
Note that there is no variable expansion in the specified paths. If, for example, you add $HOME/bin
to a file in /etc/paths.d
, you're going to be disappointed. $HOME
will not expand to your home directory, and you'll be left with a PATH
that contains the literal string $HOME/bin
.
Any user-specified paths in e.g. ~/.bashrc
are added after the above complete, since those user files are executed later in the shell start cycle.