You installed a tool but the shell says command not found. Learn how PATH works, where to add directories, and when to run hash -r or reload your rc file.
The short answer
#The shell cannot find the program because the directory it was installed into is not on your PATH, or your current shell has not picked up the change yet. Find where the binary lives, add that directory to PATH in your shell's startup file, then reload it.
_10# Example: the tool was installed into ~/.local/bin_10echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc_10source ~/.bashrc_10hash -r
On macOS the default shell is zsh, so use ~/.zshrc instead of ~/.bashrc.
Why it happens
#When you type a command name without a slash, the shell looks through each directory listed in the PATH variable, in order, and runs the first match. If none of them contain the program, you get command not found.
_10echo "$PATH" | tr ':' '\n'
Package managers and installers often put binaries in places that are not on PATH by default, for example:
~/.local/bin(pip with--user, pipx, many install scripts)~/.cargo/bin(Rust tools)~/go/bin(Go tools)- the global bin folder of npm, pnpm or a Node version manager
/opt/homebrew/binon Apple Silicon Macs
Even when an installer edits your startup file for you, the shell you already have open read that file when it started. It will not see the change until you reload it or open a new terminal.
There is one more layer. Bash remembers where it found each command in a hash table, so it does not search PATH every time. If a command moved, or you installed a newer copy earlier in PATH, Bash may keep using the old location until you clear that cache.
How to fix it
#Find where the program was installed
Check the installer's output first. If it scrolled away, these help:
_10# Does the shell already know about it?_10command -v mytool_10type -a mytool_10_10# Where did the package manager put it?_10npm prefix -g # npm global bin lives in this folder's bin_10pip show -f mypackage # lists installed files_10ls ~/.local/bin ~/.cargo/bin ~/go/bin 2>/dev/null
Add the directory to PATH in the right file
Put the export in the file your shell reads for interactive sessions:
| Shell | File to edit |
|---|---|
| Bash on Linux | ~/.bashrc |
| Bash on macOS (login shells) | ~/.bash_profile |
| zsh (macOS default) | ~/.zshrc |
_10export PATH="$HOME/.local/bin:$PATH"
Putting the new directory first means its programs win over older system copies. Putting it last (PATH="$PATH:$HOME/.local/bin") means system copies win. Pick deliberately.
On many Linux distributions, ~/.bash_profile or ~/.profile sources ~/.bashrc, so editing ~/.bashrc covers both login and non-login shells. If you are unsure, check that file for a line that sources ~/.bashrc.
Reload the shell
_10source ~/.bashrc # or: source ~/.zshrc
Opening a new terminal tab works too. Running exec "$SHELL" -l replaces the current shell with a fresh login shell.
Clear the command cache
If the command exists on PATH but the shell still runs an old copy, or reports No such file or directory for a path that has since moved, clear the hash table:
_10hash -r # Bash_10rehash # zsh
Check scripts, cron and CI separately
Non-interactive shells, cron jobs, systemd services and CI runners do not read ~/.bashrc. If a command works in your terminal but not in a script or job, either use the full path to the binary or set PATH at the top of the script or job definition.
_10#!/usr/bin/env bash_10export PATH="$HOME/.local/bin:$PATH"_10mytool --version
Common pitfalls
#- Using single quotes inside the export, such as
export PATH='$HOME/bin:$PATH'. Single quotes stop expansion, soPATHbecomes the literal text and almost every command breaks. Use double quotes. - Overwriting
PATHentirely withexport PATH="$HOME/bin", which removes/usr/binand friends. Always include the existing$PATH. - Editing
~/.bashrcwhile your shell is actually zsh. Check withecho "$SHELL"orps -p $$. - Adding the same line many times while experimenting. It works but makes
PATHlong and confusing; tidy it up. - Installing with
sudo npm install -gorsudo pip installto make a command appear. This can create permission problems later. Prefer a user-level install directory on yourPATH.
Related reading
#Was this resource helpful?