The Linux terminal is one of the fastest, most powerful and convenient ways of doing just about anything on your Linux machine. However, if you’re new to the terminal, it’s easy to get overwhelmed by the hundreds of commands and thousands of smaller tweaks you can make to those commands.
It’s not uncommon for beginners to make mistakes when typing commands in the terminal, getting them wrong and then being perplexed by the error output shown by the terminal.
In this article, we’re taking a look at what to do if you get a ‘Bash: Command not found’ error in Linux.
Also read: How to use Journalctl to read Linux logs?
What causes the ‘Bash command not found‘ error?
The error is pretty self-explanatory. For those who can’t guess what went wrong, the error arises when Bash can’t recognise the command you’re trying to execute. There are three major reasons why this might happen.
- The command itself is incorrect.
- The utility you’re trying to run isn’t installed.
- The utility is set to the wrong path.
We’ll be going over all three of these issues in this article.
How to fix ‘Bash command not found‘?
Here are three fixes you can try out to resolve the Bash command not found issue.
Try checking the command
The first thing you should do is check your command for typos or spelling mistakes. Make sure you’ve gotten everything right, including any hyphens or underscores that the command syntax might dictate. Make sure you’ve got the right characters and that the commands are in the right case.
Also read: How to find large files in Linux?
Try installing the missing package
The second reason you might face this issue is that the package or module you’re trying to run isn’t installed on your machine yet. You can check whether or not a package is installed using dpkg.
dpkg -s package-name
To counter this, try installing the package using apt or apt-get
sudo apt install package-name
Or
sudo apt-get install package-name
The Linux terminal will even give you suggestions about what packages to install depending upon what commands you enter.
Check the package path
Once you type a command and execute it, the Linux subsystem checks all system paths for the corresponding utility and, once found, runs it to complete the user’s request. Now, if you’ve installed the package you’re trying to run, but it’s not in the system path where Linux is looking for it, it’s just as good as not being installed.Â
If you’re sure that you’ve got the package installed but suspect that it’s not on the right path, follow these steps to add the command’s path to Linux.
Step 1: Use the whereis or which commands to find the package’s path.
whereis package-name
Or
which package-name
Step 2: Once you know your package’s path, use the export command to add the path we saw in step one to the system path variable.
export PATH=$PATH: /enter/path/here
Step 3: Run the following command to save your changes.
source ~/.bashrc
Now try running the command again and you should be good to go.
Also read: Debian vs Ubuntu: Which Linux distro should you pick?