Suggest Installation Of Packages When Running An Unavailable Command


As you may already know, when we run an unavailable command, we will get an error message – “bash: command not found”. The problem is most of us don’t know which packages provides that particular command. Not anymore. Today, I have stumbled upon an useful utility called “command-not-found” that helps you by suggesting installation of packages when running an unavailable command.

Let us say you want to run a command “leafpad”, and it is not available in your Linux system. You are not sure which packages provides this command. This is where “command-not-found” utility comes in help. It will automatically search the official repositories, when entering an unrecognized or unavailable command. It uses a cache of existing programs and their associated packages to help users in their day-to-day command line work.

Suggest Installation Of Packages When Running An Unavailable Command

Installing command-not-found utility

command-not-found utility is available in AUR. So, you can install it using AUR helpers such as Yaourt or Packer.

yaourt -S command-not-found


packer -S command-not-found

Also, pkgfile package provides command-not-found hook. Just install pkgfile to use command-not-found utility.

sudo pacman -S pkgfile

Once it is installed, edit your .bashrc file:

vi ~/.bashrc

Add the following line at the end to enable it.

source /usr/share/doc/pkgfile/command-not-found.bash

Update the changes made using command:

source ~/.bashrc

On Ubuntu and its derivatives, it comes pre-installed.

Just in case if it is not installed already, you can install it as follows.

sudo apt-get update
sudo apt-get install command-not-found


Now, run any unavailable command, say leafpad:

It will suggest you which package provides this command. Here is the output from my Arch Linux system.

$ leafpad 
leafpad may be found in the following packages:  
extra/leafpad /usr/bin/leafpad

As you see in the above output, the “leafpad” command is provided by leafpad- package.

Let us try another command on Ubuntu:

$ emacs
The program 'emacs' can be found in the following packages:
 * emacs24
 * emacs24-nox
 * e3
 * emacs23
 * emacs23-lucid
 * emacs23-nox
 * emacs24-lucid
 * jove
Try: sudo apt-get install <selected package>

This is just an example. This utility will suggest installation of packages when you run any unavailable command. Once you removed this utility, it won’t suggest anything. It merely displays an output something like below.

"bash: emacs: command not found"

Hope this helps.


Thanks for stopping by!

Help us to help you:

Have a Good day!!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.