[KongchangAI]
Concept环境变量PATH / PATH环境变量

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

Timeline (last 90 days)

Oct 17

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.

Unverified50%
Oct 17

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.

Unverified50%
Oct 12

When adding an executable directory under the home directory to PATH, one should use $HOME rather than ~, written as export PATH="$HOME/bin:$PATH".

Unverified50%
Oct 12

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.

Unverified50%
Oct 12

One should avoid using the form export PATH="~/bin:$PATH", because ~ will not be expanded by system calls.

Unverified50%
Oct 12

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.

Unverified50%
Oct 12

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".

Unverified50%
Oct 12

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.

Unverified50%
Oct 12

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.

Unverified50%
Sep 17

Adding the Ollama installation directory to the system PATH environment variable allows the ollama command to be invoked globally from any location.

Unverified50%

4 more timeline events

All Facts (14)

Verified

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%
Verified

PATH is an environment variable in operating systems that tells the system which directories to search for executable programs.

65%
Unverified

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.

50%
Unverified

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.

50%
Unverified

When adding an executable directory under the home directory to PATH, one should use $HOME rather than ~, written as export PATH="$HOME/bin:$PATH".

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

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.

50%
Unverified

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".

50%
Unverified

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.

50%
Unverified

One should avoid using the form export PATH="~/bin:$PATH", because ~ will not be expanded by system calls.

50%
Unverified

If 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%
Unverified

Adding the Ollama installation directory to the system PATH environment variable allows the ollama command to be invoked globally from any location.

50%
Unverified

When installing Python, the "Add Python to PATH" checkbox must be checked; otherwise, the command line will not recognize Python.

50%

Source Articles