Let’s review the concept of a PATH.
The PATH is defined in your shell profile (.bash_rc
or .zshrc
) and looks like a variable $PATH. It is typically to see a $PATH string in here that contains several directories separated by colons (:), like so:
This tells your terminal (your shell prompt), where to look for commands you type. Specifically, when you type a shell prompt, it looks in the first location first, then if it doesn’t find a corresponding shell command, it then looks into the next location, and so on.
You might be using a terminal command you have never used before— like python
, or openssl
or node
. You will often want to know if and where the given executable lives in your system (in your path directories, as explained above).
For this, you use the which command, like so:
which pyhon
Here, we ask the operating system if and where Python is installed.
which brew
Here, we ask the operating system if and where the Node executable is installed.
which node
Here, we ask the operating system if and where the Node executable is installed.
If the shell prompt doesn’t find the thing specified, it says: “___ not found”
So when you encounter a new Unix command that you will need to use, your first step will be to use which
to find out if it exists at all.
You also will often use which to see where the command lives. This can give you important information like whether or not you are using the system command — the one that came with your operating system— or you are using one that you installed using a package manager.
In the next lesson, we’ll learn about package managers, which we will use to install new Unix commands when we need them.