bash: command not found

Bash: command not found: fix PATH and shell config

When bash says 'command not found' but the program is installed, it's usually a PATH issue or a broken symlink. Here's how to check and fix it fast.

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 ~/bin or /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

  1. Find the actual location of the command. Use which, type, or find if you don't know. For example:
    which node
    /usr/bin/which: no node in (...PATH...)
    find / -name node -type f 2>/dev/null | head -5
    If you find it in /usr/local/bin, that's your directory.
  2. Check your current PATH.
    echo $PATH
    Compare it with the directory from step 1. If it's missing, that's the problem.
  3. Add the directory to PATH in your shell config. Open ~/.bashrc (or ~/.zshrc if you use zsh) and append a line:
    export PATH="/usr/local/bin:$PATH"
    Notice I put the new directory before $PATH. That way it takes precedence over older entries. It matters if you have multiple versions of a tool.
  4. Reload your config with source ~/.bashrc or just open a new terminal. Then test with which command and run it.
  5. Clear the hash table. If you moved or removed a binary, bash might still remember the old path. Run hash -r to 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/mytool

But 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.

Related Errors in Linux & Unix
null Fix Kernel Panic: VFS Unable to Mount Root Filesystem Permission Denied Flatpak 'Permission Denied' Install Fix on Linux Your Hostname Keeps Reverting After Reboot? Here's the Fix EDQUOT (122) Fix 'Disk quota exceeded' errors on Linux

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.