While using the terminal of your Linux system, you will receive the
Command Not Found error whenever a command you are entering is not accessible. In most cases, this could be due to a simple typo, or it could mean that you do not have the command installed yet. It could also indicate that the command is just missing from your system’s PATH environment variable, which is another easy thing to fix.
In this tutorial, we will show you how to fix the
Command Not Found error on Linux. We will go over the most common issues that cause this error, and cover the steps necessary to implement a solution that remedies the problem. Follow along with us below to find out what is causing the error to occur and how to fix it.
In this tutorial you will learn:
- How to install a command if it is missing
- How to check the whole path to a command’s executable
- How to add a command’s directory to PATH environment variable
- How to add executable permissions to a command
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Solving the ‘Command Not Found’ Error on Linux – Troubleshooting Methods
Since there are various issues that could be causing the error to occur, we will run through some steps to troubleshoot it below. We will start with the simplest solutions, and graduate to more in depth problem fixing if the error persists.
The simplest explanation is that you are typing the command incorrectly. The Linux terminal is ordinarilly unforgiving about typos, so ensure that your command and its options and arguments have been typed correctly before proceeding with additional troubleshooting steps below.
- Although your Linux system comes with a lot of basic commands by default, a lot more can be installed to extend the functionality of your system. If you are getting the
Command Not Founderror, consider that the requisite package may not be installed.
$ curl Command 'curl' not found, but can be installed with: sudo snap install curl # version 7.87.0, or sudo apt install curl # version 7.81.0-1ubuntu1.7
As you can see in the output above, when running the curl command on our system, we receive the error but also get some suggestions about how to install it so we can use it. Your terminal may or may not give you package suggestions if a command is missing. A quick internet search will tell you how to install the command that you are missing.
- If you are sure that the command is installed, but you still receive the same error, then use the
whichcommand to check if the executable file is stored in your PATH environment variable. As an example, we will check the full path to the
$ which curl
- If the
whichcommand returns some output, then it is possible that your current user does not have executable permissions on the command’s binary file. You could change the permissions with the following command. Substitute the example path below with the actual path to your command’s binary:
$ chmod +x /usr/bin/curl
- If the output from the
whichcommand is blank, then the executable file’s directory needs to be added to the PATH environment variable. Check your currently configured directories with this command:
$ echo $PATH
- To add a directory to $PATH permanently, we’ll need to edit the
.bashrcfile of the user you want to change. Use nano or your favorite text editor to open the file, stored in the home directory.
$ nano ~/.bashrc
- At the end of this file, put your new directory that you wish to permanently add to $PATH. Note that
/path/to/curlis just an example below, and you should replace that directory with the one where your command is actually stored.
- Save your changes and exit the file. Afterwards, execute the following command to make the changes take effect in your current session. Alternatively, you can log out or reboot the system.
$ source ~/.bashrc
In this tutorial, we saw how to troubleshoot the
Command Not Founderror on a Linux system. Every user will eventually encounter this error because of typos or because the command they need is not installed by default. This is an easy fix as the vast majority of commands you will use can be installed via your system package manager. You may also encounter the error if your command’s directory has not yet been added to PATH, but this is another easy fix as we saw in the steps above.