Bash Command Not Found, Common Reasons and Solutions

29/12/2020
Most of the time in Linux OS we run commands and programs by typing the commands in the Terminal program. However, sometimes when we run the command, we receive an error “bash :command not found”. There can be many reasons for receiving this error. Sometimes, with the minimal installation of OS, we do not see most of the commands in our system. As in minimal deployment, only packages are installed which are necessary to run the operating system while the others are skipped. While sometimes maybe the program is already installed but it is corrupted. This error also occurs if you type the command incorrectly. Therefore, we need to identify the reasons that are causing this error and then need to resolve it.

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:

$ dpkg –s package-name

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:

$ dpkg –s apt-fast

Solution

In case the package is missing from the system, then you will have to install it using the apt-get command as follows:

$ sudo apt-get install package_name

In above case, it would be:

$ sudo apt-get install apt-fast

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.

$ whereis apt-fast

Or

$ which apt-fast

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:

$ echo $PATH

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:

$ export PATH=$PATH:/usr/sbin

Now confirm the path you have added using the following command:

$ echo $PATH

To save the changes, run the following command in Terminal

$ source ~/.bashrc

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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

30 Bash loop examples

Three types of loops are used in bash for various purposes. These are for, while and until loops. The different uses of...
29/12/2020

BASH Heredoc Tutorial

How to use Here Document in bash programming A block of code or text which can be redirected to the command script or interactive...
28/12/2020

How to use Variables in Bash Programming

Variables work as temporary storage for any programming language. The coder needs to have a clear concept of using different...
28/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua proxy v4 chạy socks5 để chơi game an toàn, tốc độ cao
18/05/2024

Thuê mua proxy Telegram trọn gói, tốc độ cao, giá siêu hời
18/05/2024

Thuê mua proxy Viettel ở đâu uy tín, chất lượng và giá tốt? 
14/05/2024

Dịch vụ thuê mua proxy US UK uy tín, chất lượng số #1
13/05/2024

Thuê mua proxy Việt Nam: Báo giá & các thông tin MỚI NHẤT
13/05/2024