Quick answer
Run echo $PATH, check if the directory containing the command is listed. If not, add it with export PATH="/path/to/bin:$PATH" and reload your shell config.
Why this happens
The shell doesn't look for executables all over your filesystem. It only checks the directories listed in the PATH environment variable, in order. When you type somecommand, bash searches each directory in PATH for an executable file with that name. If it doesn't find one, you get "command not found" — even if the binary is sitting right there in /usr/local/bin.
So the real question isn't "where is the command?" but "why isn't its directory in my PATH?" Often the answer is one of these:
- You installed software to a location that isn't in the default PATH (like
~/binor/opt/tool/bin). - Your shell config (
.bashrc,.zshrc) overwrote PATH instead of appending to it. - You're using a non-interactive shell that doesn't load your config files.
- You have a broken symlink that points to a nonexistent target.
- You just installed a program and the shell's hash table still remembers the old location (or none).
The error is frustrating because it happens right after you followed a install guide that said "all done." But the fix is usually straightforward.
Step-by-step fix
- Find the actual location of the command. Use
which,type, orfindif you don't know. For example:
If you find it inwhich node /usr/bin/which: no node in (...PATH...) find / -name node -type f 2>/dev/null | head -5/usr/local/bin, that's your directory. - Check your current PATH.
Compare it with the directory from step 1. If it's missing, that's the problem.echo $PATH - Add the directory to PATH in your shell config. Open
~/.bashrc(or~/.zshrcif you use zsh) and append a line:
Notice I put the new directory beforeexport PATH="/usr/local/bin:$PATH"$PATH. That way it takes precedence over older entries. It matters if you have multiple versions of a tool. - Reload your config with
source ~/.bashrcor just open a new terminal. Then test withwhich commandand run it. - Clear the hash table. If you moved or removed a binary, bash might still remember the old path. Run
hash -rto reset it.
Alternative fixes when the main one doesn't work
Check for broken symlinks
Sometimes which finds the command, but it's a symlink pointing nowhere. Use ls -l to see the target, and readlink -f to resolve it. If the target doesn't exist, recreate the symlink or reinstall the package.
Reinstall or reinstall to a PATH location
If you installed via package manager and it puts binaries in /opt or /usr/games, those might not be in PATH. You can symlink the binary into /usr/local/bin as a quick workaround:
sudo ln -s /opt/mytool/bin/mytool /usr/local/bin/mytoolBut a cleaner fix is to add the actual directory to PATH, so future updates don't break the symlink.
Non-interactive shells
If you're running a script or a cron job, .bashrc might not be loaded because it's a non-interactive shell. In that case, you need to set PATH explicitly in the script or in ~/.profile (which is read by login shells).
Check for typos in your config
I've seen export PATH="/usr/local/bin:$PATH" accidentally get overwritten later in the file. Make sure you're not resetting PATH somewhere else. Search for any other export PATH lines and verify they append, not replace.
Prevention tip
Always append to PATH, never assign it directly. Use this pattern in your config:
export PATH="$HOME/bin:$PATH"And if you're installing software manually, put a symlink in /usr/local/bin as a fallback. That directory is in PATH on most Linux distros and macOS. It saves you from editing config files every time you install something new.