Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PATH on a Mac (UNIX) system?

I'm trying to setup a project, storm from git:
https://github.com/nathanmarz/storm/wiki/Setting-up-development-environment

Download a Storm release , unpack it, and put the unpacked bin/ directory on your PATH

My question is: What does PATH mean? What exactly do they want me to do?

Sometimes I see some /bin/path, $PATH, or echo PATH.

Can someone explain the concept of PATH, so I can setup everything easily in the future without just blindly following the instructions?

like image 853
runcode Avatar asked Aug 23 '13 18:08

runcode


People also ask

What is PATH on Mac?

PATH is a system-level variable that holds a list of directories. When you enter a command in the terminal, it's shorthand for a program with the same name. The system looks in each of the PATH directories for the program corresponding to the command. When it finds a matching program, it runs it.

Where is PATH on Mac?

Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.

What is a PATH in Unix?

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command. Program files (executables) are kept in many different places on the Unix system. Your path tells the Unix shell where to look on the system when you request a particular program.

How do I find my PATH in Unix?

Type echo $PATH at the command prompt and press ↵ Enter . This output is a list of directories where executable files are stored. If you try to run a file or command that isn't in one of the directories in your path, you'll receive an error that says the command is not found.


1 Answers

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:

  • An article about $PATH (and more)
  • a related question on superuser.com
like image 168
lindes Avatar answered Oct 02 '22 18:10

lindes