How to Fix Bash Command Not Found

bash command not found

Bash command not found is something that all Linux users used to go through. In Linux OS users are mostly using the terminal to run programs and run commands, sometimes they all encounter an error – “bash: command not found”. This error can come due to many reasons from simple spelling mistakes to path errors.

As a Linux user, you may have encountered the “bash: command not found” error at some point. This error can be frustrating and may prevent you from using certain commands or running scripts.

The “bash: command not found” error occurs when the bash shell can’t find the command you are trying to run. This can be caused by a variety of factors, such as a missing package or a misconfigured PATH variable.

In this post, we will walk you through the steps you can take to troubleshoot and fix the “bash: command not found” error on your Linux system. We will cover the common causes of this error and provide step-by-step instructions for resolving it. Whether you are a beginner or an experienced Linux user, this guide will provide you with the information you need to fix this error and get back to using your system as normal.

Learn all popular tar commands

Misspelled Command

Check whether the commands that you have typed are not misspelled. All the Linux terminal commands are case-sensitive. So Check the command if it is misspelled correctly. Also, check if you have added any extra spaces among the commands. Often people unknowingly interchange characters like 1 with I or even |. So make sure all these points are checked.

Package Not Installed

If the command corresponding package is not installed in the system then you may receive the command not found error. Verify if you have installed the package. Use the command below to verify if the package is installed.

$ dpkg –s package-name

This command will let you know if you have installed the package in your system or not.

If the package is missing from your system. Then you have to install the package using the apt-get command.

$ sudo apt-get install package-name

After installing the package, now run the command again and check if the error is gone.

Learn all the zip commands

Incorrect Path

The path is an environment shell variable that is responsible to show the different directories when the shell wants to find a command. When the path is not correct we get the “bash command not found” error. It is because , when you run a command, the system searches the command in all the locations given. When the system doesn’t find the command that we run, the system throws the error.

We can see the current path using the command below.

$ echo $PATH

Path of Command

We can use the “which” or “whereis” command to find the path of the command that we want to run.

$ whereis command
eg::whereis apt-fast // apt-fast is the command
$ which command
eg::which apt-fast // apt-fast is the command

These commands will return the path of the particular command. Now check if the path is present in your current path or not.

We can add Kali Linux tools on Ubuntu

Current Path

$ echo $PATH

Running the above command gives the current directory where you are currently working. Usually, all the commands are found in /usr/bin or /usr/local/bin directory

Adding Commands path in your search path

After checking the path and if your command path is not found in the shell’s current search path, then we have to add the command path to the search path.

We have used the “which” command to find the command path. This “which” command has returned the command path. Now we have to add this command path to the current search path. To add the command path to the current search path, follow the command below.

assume the path is :: /usr/bin

$ export PATH=$PATH://usr/bin

Now we have to confirm the path we have added. To confirm use the command below.

$ echo $PATH

Once all the above steps are done. Then we have to save the changes, that we have made.

To save changes we have to use the simple command below.

$ source ~/.bashr c

Now run the command again to see if the problem got resolved.

Do you know to ping on Discord

Permission Problem

In Certain times we may not have permission to run a particular command. We know that all the Linux or Unix commands or scripts should have an executable permission set.

We can use the stat command to find the information.

$ stat /usr/bin/ls

Stat command returns much information such as permission, date, file, size, change, etc.

We can use chmod commands to set executable permissions.

$ chmod +x package-name
$ chmod +x /path-to/package-name
$ sudo chmod +x /path-to/file.sh

Some command needs privileged access, so we run the command as root or superuser.

To run as Root or super User

$ sudo command
$ sudo path-to/command
$ -u userName command2

Conclusion

In conclusion, the “bash: command not found” error can be a frustrating issue for Linux users, but it can generally be resolved by making sure that the necessary packages are installed and the PATH variable is set correctly. By following the steps outlined in this post, you should be able to troubleshoot and fix this error on your system.

It’s important to note that the “bash: command not found” error can be caused by a variety of factors, so the specific steps you need to take to fix it may vary depending on your system and the circumstances of the error. If you are unable to fix the error using the steps outlined in this post, it may be helpful to consult the documentation for your specific Linux distribution or seek additional help from the Linux community.

Overall, the “bash: command not found” error is a common issue that can generally be resolved by making sure the necessary packages are installed and the PATH variable is set correctly. By following the steps outlined in this post, you should be able to fix this error and get back to using your Linux system as normal.

Bash command not found errors are very common among Linux users. If you know how to tweak the system then half of the job is almost done. Simply follow the instruction in the article. It can solve most of the errors. Hope the article helped you. However, if you still find errors comment down. We are ready to help you.

Thank you and have a nice day.