πŸ”§ Error Fixes
Β· 5 min read
Last updated on

Linux: Command Not Found β€” How to Fix It


bash: node: command not found
zsh: command not found: docker
-bash: aws: command not found

Your shell can’t find the executable you’re trying to run. This is one of the most common terminal errors, and it always comes down to one thing: the binary isn’t in a directory listed in your PATH environment variable.

How PATH works

When you type a command like node, your shell doesn’t search your entire filesystem. It only looks in specific directories listed in the PATH variable, in order:

echo $PATH
# /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/home/user/.local/bin

The shell checks each directory left to right. If node isn’t in any of them, you get β€œcommand not found.”

# This is what the shell does internally:
# 1. Check /usr/local/bin/node β€” not found
# 2. Check /usr/bin/node β€” not found
# 3. Check /bin/node β€” not found
# ... all directories exhausted β†’ "command not found"

Fix 1: Install the missing program

The most common cause β€” the program simply isn’t installed.

# Debian/Ubuntu
sudo apt update && sudo apt install nodejs

# Fedora/RHEL/CentOS
sudo dnf install nodejs

# Arch Linux
sudo pacman -S nodejs

# macOS (Homebrew)
brew install node

# Alpine (Docker)
apk add --no-cache nodejs

Don’t know which package provides the command?

# Ubuntu/Debian β€” find which package provides a binary
apt-file search bin/node
# Or use the built-in suggestion
command-not-found node  # Suggests: sudo apt install nodejs

# Fedora
dnf provides */bin/node

# Arch
pkgfile node

Fix 2: The program is installed but not in PATH

The binary exists somewhere on your system, but the shell doesn’t know where to find it.

# Find where the binary is
which node          # If it's in PATH (won't work if that's the problem)
whereis node        # Searches common locations
find / -name "node" -type f 2>/dev/null  # Brute force search
locate node         # Fast if updatedb has run recently

# Once found, add its directory to PATH
export PATH="$PATH:/path/to/directory"

# Make it permanent β€” add to your shell config
echo 'export PATH="$PATH:/path/to/directory"' >> ~/.bashrc  # bash
echo 'export PATH="$PATH:/path/to/directory"' >> ~/.zshrc   # zsh
source ~/.bashrc  # or ~/.zshrc

Fix 3: Fix npm/pip/cargo/go global installs

Development tools install binaries to user-specific directories that aren’t in PATH by default.

npm (Node.js):

# Find npm's global bin directory
npm config get prefix
# Usually: /usr/local or ~/.npm-global

# Add to PATH
echo 'export PATH="$PATH:$(npm config get prefix)/bin"' >> ~/.bashrc
source ~/.bashrc

pip (Python):

# pip installs to ~/.local/bin
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc
source ~/.bashrc

# Verify
which flask  # Should now work

Cargo (Rust):

# Cargo installs to ~/.cargo/bin
echo 'export PATH="$PATH:$HOME/.cargo/bin"' >> ~/.bashrc
source ~/.bashrc

Go:

# Go installs to ~/go/bin
echo 'export PATH="$PATH:$HOME/go/bin"' >> ~/.bashrc
source ~/.bashrc

Fix 4: Wrong shell or shell config not loaded

If you recently installed something and it still says β€œnot found,” your shell config might not have reloaded.

# Reload your shell config
source ~/.bashrc    # bash
source ~/.zshrc     # zsh
exec $SHELL         # Restart the shell entirely

# Check which shell you're using
echo $SHELL
# /bin/bash or /bin/zsh or /bin/fish

Common issue on macOS: The default shell is zsh, but many tutorials show bash commands. If you added something to ~/.bashrc but you’re using zsh, it won’t be loaded. Use ~/.zshrc instead.

Fix 5: Snap/Flatpak/AppImage binaries

Programs installed via Snap or Flatpak use different paths:

# Snap binaries are in /snap/bin
export PATH="$PATH:/snap/bin"

# Check if snap is the issue
snap list | grep program-name
ls /snap/bin/

# Flatpak apps are run differently
flatpak run org.program.Name

Fix 6: Check for typos and renamed commands

# Common mistakes:
python     # β†’ python3 (on modern systems)
pip        # β†’ pip3
docker-compose  # β†’ docker compose (v2, no hyphen)
apt-get    # β†’ apt (modern shorthand)
npx        # not npn or npm x

# Check if it exists under a different name
type python3
which python3

Fix 7: Virtual environment not activated

For Python projects, tools installed in a venv aren’t available globally:

# ❌ Not in venv
flask run  # command not found

# βœ… Activate the venv first
source .venv/bin/activate
flask run  # Works

For Node.js, locally installed packages aren’t in PATH:

# ❌ Locally installed, not global
eslint .  # command not found

# βœ… Use npx to run local packages
npx eslint .

# βœ… Or use the full path
./node_modules/.bin/eslint .

Fix 8: PATH was overwritten instead of appended

A common mistake in shell config files:

# ❌ This REPLACES your entire PATH
export PATH="/my/custom/dir"

# βœ… This APPENDS to your existing PATH
export PATH="$PATH:/my/custom/dir"

# βœ… Or prepend (your dir takes priority)
export PATH="/my/custom/dir:$PATH"

If you accidentally overwrote PATH, open a new terminal (it reloads from config) or run:

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.local/bin"

Debugging checklist

# 1. Is it installed at all?
which command-name
whereis command-name

# 2. What's in your PATH?
echo $PATH | tr ':' '\n'

# 3. Which shell are you using?
echo $SHELL

# 4. Which config file is loaded?
# bash: ~/.bashrc (interactive) or ~/.bash_profile (login)
# zsh: ~/.zshrc
# fish: ~/.config/fish/config.fish

# 5. Is it a shell built-in or alias?
type command-name

FAQ

Why does it work with sudo but not without?

sudo uses root’s PATH, which includes /usr/sbin and /sbin. Your user’s PATH might not include these. Add them: export PATH="$PATH:/usr/sbin:/sbin".

Why does it work in one terminal but not another?

Different terminals might use different shells (bash vs zsh) or load different config files. Check echo $SHELL in both. Also, if you modified PATH in one terminal with export, it only applies to that session.

I installed with Homebrew but it says command not found?

Homebrew on Apple Silicon (M1/M2) installs to /opt/homebrew/bin, not /usr/local/bin. Add it to PATH:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
source ~/.zshrc

How do I make PATH changes permanent?

Add the export PATH=... line to your shell config file (~/.bashrc, ~/.zshrc, or ~/.profile). Changes made with export in a terminal only last for that session.