Select Page

Fix “command not found” error

by | Feb 15, 2024

“Command not found” is an error message you might see in the terminal when the computer can’t find the executable file or command that you have entered.

Here are some common reasons for “command not found” error:

  1. You may have made a mistake in typing the command.
  2. The command you’re trying to use might not be installed on your computer.
  3. The command could be installed, but the computer doesn’t know where to find it.
  4. Sometimes, you need special permission to run certain commands, and you don’t have that permission at the moment.

Check for typos of the command

Double-check the spelling of the command. Ensure you’ve typed it correctly.

One of the main reasons for the “command not found” error is often a simple typo or misspelling. It’s crucial to review the command’s spelling carefully before trying to execute it.

Take a close look at the spelling, including capitalization, to ensure accuracy.

Linux shells offer an autocomplete feature. After typing part of a command, you can press the TAB key to let the shell automatically complete the command or suggest possible commands starting with the letters you entered.

If you’ve used a command before, you can use the “history” command to see a list of previously run commands. This command is handy when you want to quickly remember and run a command you used before.

To search for a specific command in your history, you can use the following command:

history | grep 'pattern'

This command will display the command history containing the specified ‘pattern’.

The history command is built into the shell and is available on most Linux distributions. You can use it in various shells like bash, zsh, csh, etc. It’s particularly useful for recalling and repeating commands, especially for repetitive tasks or troubleshooting.

Verify if the command is installed

To verify if the command is installed, another common reason for the “command not found” error, you can use either the “which [command]” or “whereis [command]” command.

The “which” command displays the path of the executable linked with the command. For instance, typing “which ls” will reveal the path of the “ls” command.

On the other hand, the “whereis” command shows the location of binary, source, and manual page files related to a command. For instance, typing “whereis ls” will display the paths of the binary, source, and manual page of the “ls” command.

If the command isn’t installed, the “which” command will return “no <command> in” and the “whereis” command will return “<command>:” with nothing after the colon.

In such cases, you’ll need to install the package.

The command to install a package in Linux depends on the distribution you’re using. The most common package managers are apt (Debian/Ubuntu) and yum (Red Hat/CentOS).

To install a package using apt, the command is:

sudo apt install package_name

To install a package using yum, the command is:

sudo yum install package_name

If you’re unsure which package you need to install, you can use the “yum provides” command.

For instance, to check which package the “ls” command is in, you can run either of the following commands:

yum provides $(which ls)


yum provides '*/ls'

This command will show you a list of packages containing the “ls” file. The output will include the package name, version, and repository the package belongs to.

Additionally, you can use the “yum whatprovides” command to check the package that provides a specific command or file. For example:

yum whatprovides '*/ls'

You can use this command to get more detailed information about a package that provides a specific command or file.

Add the command to the PATH environment variable

If the command is installed but not in a directory listed in your PATH environment variable, you can add the path to the command to your PATH.

The PATH is a variable in Linux and other Unix-like operating systems that tells the shell where to find executable files or commands.

When you type a command in the terminal, the shell searches for it in a list of directories specified in the PATH variable.

Directories in the PATH variable are separated by a colon (:) and are searched in the order they appear.

For example, if the PATH variable looks like this:


When you type a command, the shell first looks for it in the /usr/local/bin directory, then in the /usr/bin directory, and finally in the /bin directory.

If the command isn’t found in any of these directories, the shell returns a “command not found” error.

To see the current value of the PATH variable, you can run:

echo $PATH

You can add new directories to the PATH variable by editing the .bashrc or .bash_profile file in your home directory and adding the directory to the PATH variable.

export PATH=$PATH:/path/to/command

After you do this, you should be able to run the command from anywhere in the terminal.

Note that the steps mentioned above are for the bash shell. If you’re using a different shell like zsh or csh, the steps and file names will be different.

Use a superuser or root account

If you encounter a “command not found” error, you can try running the command with superuser or root privileges.

Some commands require superuser or root privileges for tasks like installing software, managing system services, or modifying system configuration.

To run a command as superuser or root, you can use the sudo command followed by the command you want to run. For example:

sudo apt-get update

You’ll need to enter your password before the command is executed.

Alternatively, you can switch to the root account using the su command and then run the desired command. Here’s how:


After entering the root password, you can run the command without sudo:

apt-get update

Keep in mind that running commands with superuser or root privileges can be risky, as it allows you to make significant changes to the system. Use these privileges only when necessary and exercise caution.

It’s recommended to use the sudo command instead of switching to the root account. sudo lets you run commands with root privileges without logging in as the root user. Additionally, sudo logs the commands and who ran them, which is helpful for auditing purposes.


In conclusion, the “command not found” error is common in Linux terminals. To resolve it, you can verify that the command is installed, add the command’s path to the PATH variable, check for typos, or run the command with superuser or root privileges. Remember to refer to your distribution’s documentation for the correct command names as they may vary across Linux distributions.


Submit a Comment

Your email address will not be published. Required fields are marked *

Looking For Something?

Follow Us

Related Articles

How to create Bootable USB and install Ubuntu

How to create Bootable USB and install Ubuntu

Deciding which version of Linux to put on your computer can be hard because there are a lot of options, and each one has its own unique features. One choice that many people like is Ubuntu. Some say it's one of the top Linux options out there. It's easy to use, you...

Chmod Command – How to Change File Permissions in Linux

Chmod Command – How to Change File Permissions in Linux

Understanding File Permissions in Linux In the world of Linux, file permissions play a vital role in ensuring the security and privacy of your files and directories. The chmod command, short for "change mode," is a powerful tool that allows users to modify the...

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!