PATH
An operating system environment variable used to locate executable files. It contains a list of directory paths, and the system searches these directories in order for the executable file corresponding to a command.
Core Facts
Checking "Add to PATH" during Node.js installation automatically adds the installation path to the system environment variable PATH, allowing the system to recognize the node and npm commands from any location.
PATH is an environment variable in operating systems that tells the system which directories to search for executable programs.
Timeline (last 90 days)
After installing Node, it is recommended to restart the terminal or computer to refresh the PATH environment variable; otherwise, commands such as node and npx may not be found.
A global npm install (`-g`) downloads the package to the global node_modules directory and creates an executable entry in Node's bin directory, which is in PATH by default; terminals that are already open will not pick up PATH changes, so the terminal needs to be reopened.
When adding an executable directory under the home directory to PATH, one should use $HOME rather than ~, written as export PATH="$HOME/bin:$PATH".
The root cause of ~ sometimes working and sometimes failing in PATH is that it can only be expanded when some intermediate link happens to invoke the shell to handle it.
One should avoid using the form export PATH="~/bin:$PATH", because ~ will not be expanded by system calls.
Placing relative paths (such as . or ./bin) in PATH brings security risks: when executing commands in an untrusted directory, a malicious program with the same name may be run unexpectedly.
When the operating system looks up an executable file, it searches one by one through the directories listed in PATH in order; putting . into PATH causes the system to preferentially look for a program with the same name in the current directory, and an attacker can place a malicious executable with the same name (such as ls, git, python) to execute malicious code; this type of attack was historically called "current directory hijacking".
PATH should contain only explicit absolute paths; $HOME expands to an absolute path, which meets the requirement, while whether ~ is expanded depends on who parses it and is full of uncertainty.
The contents of the PATH environment variable, when read by a system call (such as execvp), do not go through the shell's expansion process, so a ~ in PATH is treated as an ordinary character-based directory.
Adding the Ollama installation directory to the system PATH environment variable allows the ollama command to be invoked globally from any location.
4 more timeline events
All Facts (14)
Checking "Add to PATH" during Node.js installation automatically adds the installation path to the system environment variable PATH, allowing the system to recognize the node and npm commands from any location.
75%VerifiedPATH is an environment variable in operating systems that tells the system which directories to search for executable programs.
65%UnverifiedAfter installing Node, it is recommended to restart the terminal or computer to refresh the PATH environment variable; otherwise, commands such as node and npx may not be found.
50%UnverifiedA global npm install (`-g`) downloads the package to the global node_modules directory and creates an executable entry in Node's bin directory, which is in PATH by default; terminals that are already open will not pick up PATH changes, so the terminal needs to be reopened.
50%UnverifiedWhen adding an executable directory under the home directory to PATH, one should use $HOME rather than ~, written as export PATH="$HOME/bin:$PATH".
50%UnverifiedThe contents of the PATH environment variable, when read by a system call (such as execvp), do not go through the shell's expansion process, so a ~ in PATH is treated as an ordinary character-based directory.
50%UnverifiedThe root cause of ~ sometimes working and sometimes failing in PATH is that it can only be expanded when some intermediate link happens to invoke the shell to handle it.
50%UnverifiedPlacing relative paths (such as . or ./bin) in PATH brings security risks: when executing commands in an untrusted directory, a malicious program with the same name may be run unexpectedly.
50%UnverifiedWhen the operating system looks up an executable file, it searches one by one through the directories listed in PATH in order; putting . into PATH causes the system to preferentially look for a program with the same name in the current directory, and an attacker can place a malicious executable with the same name (such as ls, git, python) to execute malicious code; this type of attack was historically called "current directory hijacking".
50%UnverifiedPATH should contain only explicit absolute paths; $HOME expands to an absolute path, which meets the requirement, while whether ~ is expanded depends on who parses it and is full of uncertainty.
50%UnverifiedOne should avoid using the form export PATH="~/bin:$PATH", because ~ will not be expanded by system calls.
50%UnverifiedIf the command does not take effect after configuring the environment variable, it may be due to caching, and restarting the computer can resolve the issue.
50%UnverifiedAdding the Ollama installation directory to the system PATH environment variable allows the ollama command to be invoked globally from any location.
50%UnverifiedWhen installing Python, the "Add Python to PATH" checkbox must be checked; otherwise, the command line will not recognize Python.
50%