๐ฃ Path and Executables
The PATH environment variable controls which executables the shell finds when you type a command name.
๐งญ What Is PATH?
PATH is a colon-separated list of directories where the shell looks for programs:
1 2 | |
When you run a command like ls, the shell checks each directory until it finds the binary.
๐ต๏ธโโ๏ธ Finding Executables
Use which or command -v to locate a program:
1 2 3 4 5 | |
command -v is preferred because it also works with functions and aliases.
๐งฑ Adding Directories to PATH
Suppose you installed a tool in ~/bin. To make it globally accessible:
Temporarily:
1 | |
Permanently:
Edit your profile (.bashrc, .zshrc, etc.):
1 2 | |
Always prepend new entries so they take precedence over system defaults.
๐งช Resolving Conflicts
Multiple binaries with same name? The first match wins:
1 2 3 | |
Use full path to call specific version:
1 | |
๐งพ Summary
- PATH defines where the shell searches for commands.
- Add custom directories early in the PATH to override system versions.
- Use
whichorcommand -vto verify resolution order. - Be cautious with naming conflicts between system and local binaries.
๐ Continue to: Redirections