In this article, we will explain the possible reasons for receiving the “bash command not found” error when attempting to run a command in Terminal. Along with this, we will also discuss some feasible solutions that you should try in order to remove the error and successfully run the commands and programs.
Bash command not found: Common Reasons and solutions
Misspell Error
Misspelling a command is a common mistake that users make when running a command in a shell. All commands for Linux and UNIX are case sensitive and we should type the right command spelling.
Solution
Check for:
- Spelling mistake
- Spaces among command and the various options
- Incorrect interchange of characters like 1 with I or l
- Interchanging of uppercase letters with lowercase letters
Package Not Installed
Sometimes, you receive the “command not found error” because the package is not installed on your system or has been corrupted. To verify if the package is installed in your system, run the following command in Terminal:
It will return the output with the results showing whether the package is installed in your system or not. For instance, you want to run apt-fast command and you are receiving the command not found error, then run the following command in order to check if is installed on your system:
Solution
In case the package is missing from the system, then you will have to install it using the apt-get command as follows:
In above case, it would be:
Once the package is installed, try running the command in order to check if the error is removed.
Path Is Not Correct
Another major reason you get the “bash command not found” error is that the path it is looking for is incorrect. When a user enters a command, the system searches it for in all locations it knows and when it does not find the command in the searched locations, it returns the error.
Solution
Step 1: Find the path of command
First, find the path of the command where it is installed by using “which” or “whereis” command. For instance, you are trying to run the apt-fast command and it is giving the “command not found” error. Run the following command in order to find the location of the apt-fast command.
Or
Note down the path in the above output and then find if the above path is in your current search path or not.
Step 2: Find the current search path
To view the current search path, run the following command in Terminal:
PATH (Written in upper case letters) guides the shell about locations to search for the executable files. Most of the commands are commonly found in /usr/bin, /bin and /usr/local/bin paths. When we run any command, it is actually running from these directories.
Step 3: Add command’s path to your search path
If the path of the command is not in your shell’s current search path, then try to add this to your search path as follow:
From the “which” search results, we found that apt-fast is installed in /usr/sbin. To add /usr/sbin to the current search path, use the following command:
Now confirm the path you have added using the following command:
To save the changes, run the following command in Terminal
Now again try running the command for which you were receiving the error and see if the error has resolved.
Bash command not found error is encountered by almost every system administrators and users. In this article, we have learned a few solutions which you should give a try in order to resolve this error.
from Linux Hint https://ift.tt/2T4OCGg
0 Comments