bash: command not found — PATH Environment Variable and Binary Location Issues
About bash: command not found
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. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Check current PATH: 'echo $PATH' to see all directories being searched. Find the binary location: 'find / -name binary-name -type f 2>/dev/null' or check the installer output. Add to PATH in ~/.bashrc: 'export PATH="$HOME/.local/bin:$PATH"' then 'source ~/.bashrc'. For sudo: use the full path 'sudo /full/path/to/command' or edit /etc/sudoers secure_path. Verify with: 'which command-name' or 'type command-name' after adding to PATH. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Where should I add PATH modifications?
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.
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