🔧 Error Fixes
· 2 min read
Last updated on

Linux: Command Not Found — How to Fix It


bash: command not found

What causes this

Your shell can’t find the executable you’re trying to run. The shell searches directories listed in your PATH environment variable — if the binary isn’t in any of those directories, you get this error.

Common causes:

  • The program isn’t installed
  • The program is installed but not in your PATH
  • You installed it with a different package manager (snap, flatpak, brew) that uses a different path
  • A typo in the command name
  • You installed something with pip, npm, or cargo and the bin directory isn’t in PATH
  • You’re in a different shell than expected (bash vs zsh vs fish)

Fix 1: Install the missing command

# Debian/Ubuntu
sudo apt update && sudo apt install package-name

# Fedora/RHEL
sudo dnf install package-name

# Arch
sudo pacman -S package-name

# macOS
brew install package-name

Not sure which package provides the command? On Ubuntu:

apt-file search bin/command-name
# or
sudo apt install command-not-found && command-name

Fix 2: Add the binary to your PATH

# Check current PATH
echo $PATH

# Find where the binary actually is
which command-name
find / -name "command-name" -type f 2>/dev/null

# Add to PATH temporarily
export PATH="$PATH:/path/to/bin"

# Add permanently — edit your shell config
echo 'export PATH="$PATH:/path/to/bin"' >> ~/.bashrc
source ~/.bashrc

For zsh (default on macOS):

echo 'export PATH="$PATH:/path/to/bin"' >> ~/.zshrc
source ~/.zshrc

Fix 3: Fix npm/pip/cargo global installs

These tools install binaries to user-specific directories:

# npm — find global bin directory
npm config get prefix
# Add to PATH: export PATH="$PATH:$(npm config get prefix)/bin"

# pip / pipx
python3 -m site --user-base
# Add to PATH: export PATH="$PATH:$HOME/.local/bin"

# cargo (Rust)
# Add to PATH: export PATH="$PATH:$HOME/.cargo/bin"

Fix 4: Check for typos and aliases

# Did you mean...
npx  # not npn
python3  # not python (on some systems)
docker compose  # not docker-compose (v2)

# Check if it's an alias
alias | grep command-name
type command-name

Fix 5: Use the full path

If you know where the binary is, use the absolute path:

/usr/local/bin/node script.js
~/.local/bin/aws configure

How to prevent it

  • After installing dev tools, verify they work immediately with which tool-name
  • Add common bin directories to your PATH in your shell config upfront: ~/.local/bin, ~/.cargo/bin, $(npm config get prefix)/bin
  • Use a version manager like nvm, pyenv, or rustup that handles PATH automatically
  • Keep a dotfiles repo so your PATH config is consistent across machines