What Is the PATH Variable? Where the Shell Finds Programs
PATH is an environment variable holding a list of directories the shell searches, in order, to find the program behind a command you type.
When you type node or pytest, the shell does not magically know where that program lives. It walks through the directories listed in the PATH variable, left to right, and runs the first matching executable it finds. A misconfigured PATH is one of the most common reasons a CI step dies with "command not found."
How PATH works
PATH is a colon-separated list of directories (semicolon-separated on Windows). For each bare command name, the shell checks each directory in order and runs the first executable that matches. If none match, you get "command not found."
Reading and changing PATH
You can print it with echo "$PATH". To add a directory, you prepend or append it, typically writing export PATH="/new/dir:$PATH". Prepending makes your directory win over system ones; appending makes it a fallback.
Why order matters
- The first match wins, so earlier directories shadow later ones.
- Prepending a tool directory lets you override a system version.
- A duplicated or wrong entry can silently run the wrong binary.
PATH in CI
CI runners set up PATH so installed toolchains are reachable. When you install a tool into a custom location, you must add it to PATH for later steps to find it, or the job fails with "command not found" even though the install succeeded.
Persisting PATH across steps
In GitHub Actions, exporting PATH in one run: step does not carry to the next, because each step is a fresh shell. You append the directory to the special $GITHUB_PATH file instead, which makes it available to all following steps.
PATH on managed runners
Latchkey runners come with common toolchains already on PATH, so most jobs find their tools with no setup. For custom binaries you install during a job, remember that PATH changes are per-step unless you persist them.
Key takeaways
- PATH lists the directories the shell searches to resolve a command name.
- The first matching executable wins, so directory order decides which binary runs.
- In CI, a wrong or non-persisted PATH is a top cause of "command not found".