0
0
Linux-cliDebug / FixBeginner · 3 min read

How to Fix 'command not found' Error in Linux Quickly

The command not found error in Linux happens when the shell cannot find the program you typed. To fix it, check if you typed the command correctly or add the program's folder to your PATH environment variable so the shell can find it.
🔍

Why This Happens

This error occurs because Linux looks for commands only in specific folders listed in the PATH environment variable. If the command is not in any of these folders or is misspelled, the shell cannot find it and shows command not found.

bash
mycommand
Output
bash: mycommand: command not found
🔧

The Fix

First, check if you typed the command correctly. If the command is a program you installed but is not in your PATH, add its folder to PATH. For example, if the program is in /usr/local/bin, run:

export PATH=$PATH:/usr/local/bin

This lets the shell find the command. You can also run the command by giving its full path.

bash
export PATH=$PATH:/usr/local/bin
mycommand
Output
mycommand: command executed successfully
🛡️

Prevention

Always double-check your command spelling before running it. When installing new software, ensure its executable folder is in your PATH. You can add permanent PATH changes by editing your shell profile files like ~/.bashrc or ~/.profile. Using package managers also helps keep commands accessible.

⚠️

Related Errors

Other similar errors include Permission denied when you lack rights to run a command, or No such file or directory when the command path is wrong. Fix these by checking permissions with chmod or verifying the file path.

Key Takeaways

Check command spelling carefully to avoid 'command not found' errors.
Add the program's folder to your PATH environment variable to let Linux find it.
Use full command paths if the program is not in your PATH.
Make PATH changes permanent by editing shell profile files.
Use package managers to install software and manage command availability.