Environment variables and PATH
At some point you type a perfectly reasonable command and the computer responds with some variation of: command not found.
Excellent. Very informative.
Environment variables
Environment variables are named values made available to programs by their environment. They can hold configuration such as a temporary directory, a user home directory or a list of places to search for executables.
What is PATH?
PATH is an environment variable containing directories that the shell searches when you type a command without giving the full path to the program.
If Python's executable directory is on PATH, typing python can launch it. If it is not, the shell may tell you that Python cannot be found even though it is installed.
Do not add random things to PATH
Add directories deliberately and know what they contain. PATH affects which executable is found when names collide, so it is worth treating it as configuration rather than a dumping ground.
Changes may need a new terminal
If you change environment variables while a terminal is already open, that existing shell may not automatically receive the new value. Opening a new terminal is often the simplest test.
Full paths are useful for diagnosis
If a command name does not work but launching the executable by its complete path does, you have learned something useful: the program itself probably works and command discovery is the bit to investigate.
PATH is a list, not a magic folder
One thing that confused me when I first came across PATH was the name. It sounds as though it ought to contain one path.
It doesn't. PATH normally contains a list of directories. When you type a command such as python, the operating system can search those directories for a matching executable.
Why installers ask about PATH
This is why some installers offer an option such as "Add Python to PATH". They are not changing Python itself. They are making it easier for your shell to find Python when you type its command.
If you say no, Python may still be installed perfectly well. You may simply need to launch it another way or add the appropriate directory later.
Changing PATH can go wrong
Do not delete the existing value and replace it with the one directory you care about. Other programs may rely on the entries already there.
When changing environment variables, know whether you are adding, editing or removing an entry, and keep a copy of the old value if you are unsure.
When should I edit PATH?
Only when you actually need to. If a tool already works from the command line, there is no prize for editing PATH anyway.
If it does not work, first check that the program is installed and find out what command its own documentation expects you to use.
Further reading and external resources
Want to dig into this a bit more? These are good places to go next. If anything here ever disagrees with the official documentation, trust the official documentation.
Image Description