Linux 'bash: command not found' Error Fix
You type a command and get 'command not found'. Happens when PATH is broken, the package isn't installed, or the binary isn't in the right place.
You just opened a terminal on your Linux box — maybe Ubuntu 22.04, maybe CentOS 7 — and type ifconfig or htop or sometimes even ls. Instead of the output you expect, you get:
bash: ifconfig: command not found
It's jarring. You know the command exists. Maybe it worked yesterday. Now it's gone. This happens all the time, and it's almost never a real problem with your system. Let's walk through why it happens and how to fix it.
What actually causes this error
The shell — bash, in most cases — looks for the command you typed in a list of directories stored in a variable called PATH. You can see your current PATH by running:
echo $PATH
You'll get something like:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
If the command you're trying to run isn't in one of those directories, bash says command not found. That's it. Either the binary isn't there (not installed) or the directory it lives in isn't listed in your PATH.
A second, less common cause: you typed the command wrong. A single typo like ifconfig vs ifconfig? Bash won't find it. But I'm assuming you checked that already.
A third cause: the command got removed. Maybe you uninstalled a package by accident, or a system update replaced a tool with a newer version that lives in a different directory.
How to fix it — step by step
Step 1: Check if the command is installed at all
Use which or type to see if bash knows about it:
which ifconfig
If it returns nothing, or says no ifconfig in ..., then the command isn't installed. If it gives you a path like /sbin/ifconfig, then it's installed but your PATH doesn't include /sbin.
Expected outcome after this step: You'll either see a path (good) or nothing (not installed).
Step 2: Try running it with the full path
If which gave you a path, run that directly:
/sbin/ifconfig
If it works, the fix is simple: add /sbin to your PATH. If it says Permission denied, you might need sudo:
sudo /sbin/ifconfig
Expected outcome: The command runs, or you get a permission error (which means it's installed).
Step 3: Install the missing command
If which returned nothing, you need to install the package that provides that command. On Debian/Ubuntu-based systems, use apt. On Red Hat/CentOS, use yum or dnf.
First, find what package owns the command. For example, for ifconfig:
# Debian/Ubuntu
apt search ifconfig
# Or use apt-file if installed
apt-file search ifconfig
# Red Hat/CentOS
yum provides ifconfig
You'll see something like: net-tools: /sbin/ifconfig. Install it:
sudo apt install net-tools # Debian/Ubuntu
sudo yum install net-tools # CentOS 7
sudo dnf install net-tools # Fedora / CentOS 8+
Expected outcome: After install, ifconfig should work. If it doesn't, your PATH still needs fixing.
Step 4: Fix your PATH variable
If the command is installed but still not found, your PATH doesn't include its directory. You can add it temporarily for the current session:
export PATH="$PATH:/sbin"
Test it: ifconfig should now work. To make it permanent, add that same line to your shell's startup file. For bash, that's usually ~/.bashrc or ~/.bash_profile:
echo 'export PATH="$PATH:/sbin"' >> ~/.bashrc
source ~/.bashrc
Expected outcome: The command works now, and will work after you log out and back in.
Step 5: Check for a broken symlink
Sometimes the command is there but the link is broken. Run:
ls -la /usr/bin/ifconfig # or wherever it should be
If you see a red blinking link or No such file or directory, the symlink points to a missing file. Reinstall the package to fix it.
What to check if it still fails
- Did you use sudo? Some commands are only in root's PATH. Run
sudo echo $PATHand compare with your user's PATH. They can be different. - Are you in a container or minimal environment? Docker containers often strip down to bare minimum. If a command isn't in the base image, you need to install it inside the container.
- Did you check the architecture? If you're on a 64-bit system and the binary is 32-bit, it won't run without the 32-bit libraries installed.
- Is it a shell built-in? Some things like
cdorechoare built into bash. Ifechogives command not found, your shell is broken — that's a bigger problem. Re-install bash. - Did you check the man page? Run
man [command]. If that works, the command exists but isn't in your PATH. If man says No manual entry, it's not installed.
Nine times out of ten, it's either a missing package or a PATH issue. Both are easy fixes. And if you're on a newer system that uses ip instead of ifconfig, maybe just use ip addr instead. It's the modern way.
Was this solution helpful?