When you run a shell command and see the error '-bash command not found', Bash cannot locate an executable matching the name you typed. This usually happens because the command is misspelled, not installed, or not in a directory listed in your PATH environment variable.
Understanding exactly what Bash is looking for and how it searches helps you resolve the issue quickly, whether you are working locally or on a remote server.
| Aspect | Description | Likely Cause | Quick Check |
|---|---|---|---|
| Typo or Name | The command name is misspelled or uses wrong casing. | User typed gIT instead of git. |
Re-type the command carefully or copy-paste from documentation. |
| Package Not Installed | The software providing the command is missing from the system. | Trying to run htop when htop is not installed. |
Check with your distribution’s package manager if the package exists. |
| PATH Issue | The directory containing the binary is not in PATH. | Custom binaries in ~/bin are not searched by Bash. |
Run echo $PATH and verify the directory is listed. |
| Shell Session Stale | The shell’s hash table is outdated after installing new tools. | Installing a command but not refreshing Bash’s internal cache. | Use hash -r or start a new shell session. |
Diagnosing Command Not Found Errors
Diagnosis is systematic: verify spelling, check installation status, and locate binaries using built-in tools. Each step narrows down the root cause and guides you toward a targeted fix.
Verify Spelling and Case
Bash commands are case-sensitive, so Ls and ls are treated differently. Always match the exact command name as shown in documentation or help pages.
Check If Package Is Installed
Use your system’s package manager to confirm whether the software providing the command is installed. On Debian-based systems, dpkg -l | grep package or apt list --installed can help you verify.
Installing Missing Commands and Packages
If the package is missing, install it using the appropriate package manager. Installing the correct package usually adds the binary to a standard location included in PATH.
Installing on Debian and Ubuntu
Run sudo apt update && sudo apt install package to install and refresh package metadata. This places binaries in directories such as /usr/bin or /usr/local/bin, which are typically in PATH.
Installing on Red Hat and CentOS
Use sudo yum install package or, on newer releases, sudo dnf install package. These commands fetch the package and its binaries from configured repositories.
PATH and Binary Location Troubleshooting
When the command exists but Bash cannot find it, the PATH variable may be incomplete. Confirm where the binary lives and ensure that directory is included in PATH for your shell sessions.
Locate Installed Binaries
Use which command or command -v command to see if Bash finds the executable. If these return nothing, the command is not in any PATH directory.
Inspect and Update PATH
Run echo $PATH to list directories searched in order. Add missing directories to PATH in your shell profile files, such as ~/.bashrc or ~/.profile, with export PATH="$PATH:/custom/bin".
Key Takeaways for Reliable Command Availability
- Double-check spelling, case, and documentation to avoid simple typos.
- Confirm the package providing the command is installed via your package manager.
- Verify the binary resides in a directory listed in your PATH environment variable.
- Refresh the shell hash table with
hash -rafter installing or moving binaries. - Use full paths or create well-placed symlinks only when necessary and intentional.
FAQ
Reader questions
Why does a command installed with sudo still show '-bash command not found'?
The installation may have placed the binary in a directory not in your PATH, or your shell’s hash table is outdated. Try running the command with its full path, refresh the hash table with hash -r , or restart your shell session.
Can I safely create a symlink to fix the '-bash command not found' error?
Creating a symlink only makes sense if the binary exists but resides outside PATH. Point the symlink to a directory already in PATH, such as /usr/local/bin , and ensure it has executable permissions. Otherwise, install the package properly or update PATH instead.
Is it safe to add /usr/local/bin to my PATH if it is not already there?
Yes, adding /usr/local/bin is safe and common practice, since this directory is reserved for administrator-provided software. It helps Bash locate locally installed commands without affecting system directories.
What should I do if the command appears to be installed but is still not found?
Check that the binary is truly present on disk, confirm it is executable, verify your PATH includes its directory, and refresh the shell hash table with hash -r . If issues persist, reinstall the package to ensure all files are correctly placed.