bash: command not found — PATH Environment Variable and Binary Location Issues
Informationalbash errors
Overview
Fix 'command not found' errors in bash when installed programs cannot be found because the binary location is not in the shell's PATH environment variable.
Key Details
- The PATH environment variable lists directories where the shell searches for executables
- When you type a command, bash searches each PATH directory left to right for the binary
- Common PATH directories: /usr/local/bin, /usr/bin, /bin, /usr/local/sbin, /usr/sbin, /sbin
- User-installed programs (pip, npm, cargo, go) often install to paths not in the default PATH
- PATH is set in shell config files: ~/.bashrc, ~/.bash_profile, ~/.profile, or /etc/environment
Common Causes
- Binary installed to a location not in PATH (e.g., ~/.local/bin, ~/go/bin, ~/.cargo/bin)
- PATH modified incorrectly in shell config file (missing colon separator or typo)
- Using sudo which uses a different PATH than the regular user (secure_path in sudoers)
- Package installed but shell session not reloaded to pick up the new PATH entry
Steps
- 1Check current PATH: 'echo $PATH' to see all directories being searched
- 2Find the binary location: 'find / -name binary-name -type f 2>/dev/null' or check the installer output
- 3Add to PATH in ~/.bashrc: 'export PATH="$HOME/.local/bin:$PATH"' then 'source ~/.bashrc'
- 4For sudo: use the full path 'sudo /full/path/to/command' or edit /etc/sudoers secure_path
- 5Verify with: 'which command-name' or 'type command-name' after adding to PATH
Tags
bashcommand-not-foundpathenvironmentshell
Related Items
More in Bash Errors
Frequently Asked Questions
For login shells: ~/.bash_profile or ~/.profile. For interactive shells: ~/.bashrc. Most terminal emulators use interactive login shells, so ~/.bashrc is usually sufficient. For system-wide changes: /etc/environment or /etc/profile.d/*.sh.