Fixing 'bash: command not found': A Step-by-Step Guide for Linux & macOS

beginner🐧 Linux2026-03-31| Linux (Ubuntu, Debian, CentOS, RHEL), macOS, or any Unix-like environment using Bash/Zsh.

Error Message

bash: <command>: command not found
#linux#bash#terminal#sysadmin#devops

Why is the terminal rejecting your command?

You're ready to work, you type a command like docker-compose or terraform, and the terminal hits you with a frustrating wall of text: bash: command not found. It's a common speed bump for developers and sysadmins alike.

This error simply means your shell (Bash) looked through its specific list of "trusted" folders and couldn't find an executable file with that name. It doesn't always mean the software is missing. Often, the program is sitting right on your hard drive, but Bash just doesn't know where to look.

Step 1: Confirm the Software is Actually Installed

Before diving into complex configurations, check if the binary exists. Sometimes we assume a tool like curl or htop is pre-installed when it isn't. Use the which or command -v tools to probe the system.

# Check for curl
which curl
# If it returns nothing, it's not in your PATH.

If these commands return a blank line, you need to install the package. For example, on a fresh Ubuntu 22.04 LTS instance, you might need to run:

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

# CentOS/RHEL
sudo yum install curl

# macOS (using Homebrew)
brew install curl

Step 2: Audit Your $PATH Variable

If you just installed a tool like Go (standard path: /usr/local/go/bin) or Node.js and it's still not working, the $PATH variable is the likely culprit. Think of $PATH as a search map. If a directory isn't on the map, Bash won't visit it.

View your current search map by running:

echo $PATH

You will see a long string of directories separated by colons, such as /usr/local/sbin:/usr/local/bin:/usr/bin. If your tool lives in /opt/special_tool/bin and that folder isn't listed, the command will fail every time.

The Quick Session Fix

Need it to work right now? You can temporarily add a directory to your path for the current terminal window:

export PATH=$PATH:/home/linuxuser/.local/bin

The Permanent Solution

Temporary fixes vanish the moment you close the terminal. To make the change stick, you must edit your shell profile—usually ~/.bashrc for Linux or ~/.zshrc for macOS users.

  • Open the config: nano ~/.bashrc
  • Go to the very bottom and add: export PATH="$PATH:/your/custom/path"
  • Save and exit (Press Ctrl+O, Enter, then Ctrl+X).
  • Force the terminal to read the changes immediately: source ~/.bashrc

Step 3: Fix Script Permissions and Prefixes

Are you trying to run a script you just wrote, like deploy.sh? If you type deploy.sh and get "command not found," it's because Linux refuses to look in the current directory for security reasons. You must be explicit.

# This fails
deploy.sh

# This works
./deploy.sh

If you get a "Permission denied" error instead, the file isn't marked as executable. Fix it with a quick chmod:

chmod +x deploy.sh

Step 4: Use Symbolic Links for a Cleaner System

Adding ten different folders to your $PATH makes it messy and slow. A cleaner professional approach is to create a symbolic link (a shortcut) in a directory that is already in the path, like /usr/local/bin.

# Linking a standalone binary to a standard location
sudo ln -s /opt/my-app-v1.2/bin/app-exe /usr/local/bin/app-exe

Now, when you type app-exe, the system finds the link in /usr/local/bin and redirects it to the actual file in /opt.

Pro-Tip: Use 'type -a' to Debug

If you're confused about which version of a command is running (or why it's failing), use type -a. It reveals the truth behind the command:

type -a python
# Output might show:
# python is /usr/bin/python
# python is /home/user/anaconda3/bin/python

This command tells you if your tool is an alias, a built-in shell function, or a physical file. It's the fastest way to spot path conflicts when you have multiple versions of a language like Python or Ruby installed.

Summary Checklist

  • Typo Check: Did you type kubectl or kubectel? It happens to the best of us.
  • Path Awareness: 90% of these errors are solved by adding the directory to ~/.bashrc.
  • Refresh: Always run source ~/.bashrc after editing your profile.
  • Automation: If you're writing Cron jobs, never rely on $PATH. Always use absolute paths like /usr/bin/python3 instead of just python3.

Related Error Notes