This beginner tutorial shows how to go about fixing the Bash: command not found error on Debian, Ubuntu and other Linux distributions.

When you use commands in Linux, you expect to see an output. But sometimes, you’ll encounter issues where the terminal shows ‘command not found’ error.

bash command not found error

There is no straightforward, single solution to this error. You have to do a little bit of troubleshooting on your own.

It’s not too difficult, honestly. The error gives some hint already when it says “bash: command not found”. Your shell (or Linux system) cannot find the command you entered.

There could be three possible reasons why it cannot find the command:

  • It’s a typo and the command name is misspelled
  • The command is not even installed
  • The command is basically an executable script and its location is not known

Let’s go in detail on each possible root cause.

Fixing “bash: command not found” error

bash command not found error 1

Method 1: Double check the command name (no, seriously)

It is human to make mistakes, specially while typing. It is possible that the command you entered has a typo (spelling mistake).

You should specially pay attention to:

  • The correct command name
  • The spaces between the command and its options
  • The use of 1 (numeral one), I (capital i) and l (lowercase L)
  • Use of uppercase and lowercase characters

Take a look at the example below, where I have misspelled the common ls command.

command not found error

So, make double sure what you are typing.

Method 2: Ensure that the command is installed on your system

This is another common reason behind the command not found error. You cannot run a command if it is not installed already.

While your Linux distribution comes with a huge number of commands installed by default, it is not possible to pre-install all the command line tools in a system. If the command you are trying to run is not a popular, common command, you’ll have to install it first.

You can use your distribution’s package manager to install it.

command not found debian
You may have to install the missing command

In some cases, popular commands may get discontinued and you may not even install it anymore. You’ll have to find an alternative command to achieve the result.

Take the example of ipconfig command. This deprecated command was used for getting Ip address and other network interface information. Older tutorials on the web still mention using this command but you cannot use it anymore in newer Linux versions. It has been replaced by the ifconfig tool.

bash command not found error
Some popular commands get discontinued over the time

Occasionally, your system won’t find even the extremely common commands. This is often the case when you are running a Linux distribution in Docker containers. To cut down on the size of the operating system image, the containers often do not include even the most common Linux commands.

This is why Docker user stumble across things like ping command not found error etc.

ping command not found ubuntu
Docker containers often have only a few commands installed

So, the solution is to either install the missing command or find a tool that could do the same thing you were trying to do with the missing command.

Method 3: Check if it is an executable script with correct path

This is a common mistake Linux rookies make while running a shell script.

Even if you are in the same directory and try to run an executable script just by its name, it will show an error.

root@debian-test:~/scripts# sample
-bash: sample: command not found

You need to either specify the shell interpreter explicitly or its absolute path.

bash script command not found error

If you are in some other directory and try to execute the shell script without giving the correct path to the file, it will complain about not finding the file.

script file not found error

Adding it to the PATH

In some cases, you download the entire software in a tar file, extract it and find an executable file along with other program files. To run the program, you need to run the executable file.

But for that, you need to be in the same directory or specify the entire path to the executable file. This is tiresome.

Here, you can use the PATH variable. This variable has a collection of directories and these directories have the binary (executable) files of various Linux commands. When you run a command, your Linux system checks the mentioned directories in the PATH variable to look for the executable file of that command.

You can check the location of the binary of a command by using the which command:

path location

If you want to run an executable file or script from anywhere on the system, you need to add the location of the file to this PATH variable.

adding executable to path variable linux

The PATH variable then needs to be added to the rc file of the shell so that the changes made to PATH variable is permanent.

You get the gist here. It is important that your Linux system has the knowledge about the location of the executable script. Either you give the path while running it or you add its location to the PATH variable.

Did it help you?

I understand that when you are new to Linux, things could be overwhelming. But when you understand the root cause of the problem, it gradually improved your knowledge.

Here, there is no straightforward solution possible for the ‘command not found error’. I gave you some hints and pointers and that should help you in troubleshooting.

If you still have doubt or need help, please let me know in the comment section.

Leave a Comment