Przejdลบ do treล›ci

๐Ÿ›ฃ 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
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

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
$ which ls
/bin/ls

$ command -v python3
/usr/bin/python3

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
export PATH="$HOME/bin:$PATH"

Permanently:

Edit your profile (.bashrc, .zshrc, etc.):

1
2
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

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
$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 9 Apr  1 12:00 /usr/bin/python -> python3.9
-rwxr-xr-x 1 root root 5488880 Feb 10 09:00 /usr/bin/python3.9

Use full path to call specific version:

1
/usr/bin/python3.9 --version


๐Ÿงพ Summary

  • PATH defines where the shell searches for commands.
  • Add custom directories early in the PATH to override system versions.
  • Use which or command -v to verify resolution order.
  • Be cautious with naming conflicts between system and local binaries.

๐Ÿ‘‰ Continue to: Redirections