What is PATH on a Mac (UNIX) system?

PATH is a special environment variable in UNIX (and UNIX-like, e.g. GNU/Linux) systems, which is frequently used and manipulated by the shell (though other things can use it, as well).

There’s a somewhat terse explanation on wikipedia, but basically it’s used to define where to search for executable files (whether binaries, shell scripts, whatever).

You can find out what your current PATH is set to with a simple shell command:

: $; echo $PATH

(Note: the : $; is meant to represent your shell prompt; it may be something very different for you; just know that whatever your prompt is, that’s what I’m representing with that string.)

Depending on your system and prior configuration, the value will vary, but a very simple example of the output might be something like:

/usr/bin:/bin:/usr/local/bin

This is a colon(:)-separated list of directories in which to search for executable files (things like ls, et cetera.) In short, when you try to execute a command from your shell (or from within some other program in certain ways), it will search through each of the directories in this list, in order, looking for an executable file of the name you’re provided, and run the first one it finds. So that’s the concept, per your question.

From there, what this documentation is telling you to do is to add the directory where you’ve unpacked the software, and in particular its bin subdirectory, into your $PATH variable. How to do this depends a bit on which shell you’re using, but for most (Bourne-compatible) shells, you should be able to do something like this, if you’re in the directory where that bin directory is:

: $; PATH="$PATH:$PWD/bin"; export PATH

In just about all but an actual Bourne shell, this can be shortened to:

: $; export PATH="$PATH:$PWD/bin"

(I won’t bother explaining for CSH-compatible shells (because: I agree with other advice that you don’t use them), but something similar can be done in them, as well, if that happens to be your environment of choice for some reason.)

Presumably, though, you’ll want to save this to a shell-specific configuration file (could be ~/.profile, ~/.bashrc, ~/.zshrc… depending on your shell), and without reference to $PWD, but rather to whatever it expanded to. One way you might accomplish this would be to do something like this:

: $; echo "export PATH=\"\$PATH:$PWD/bin\""

and then copy/paste the resulting line into the appropriate configuration file.

Of course you could also generate the appropriate command in other ways, especially if your $PWD isn’t currently where that bin directory is.

See also:

Leave a Comment