23

I have noticed that while on Ubuntu, if I type the following:

mc

and it isn't installed, I get the message below:

The program 'mc' is currently not installed. You can install it by typing: sudo apt-get install mc

However in Debian, that is not available. It just gives a "-bash: /usr/bin/mc: No such file or directory" message. How can I implement the same functionality in bash command line on Debian? Yes, I know that if it is package suggestion that I want, I can simply do a regex search using apt-cache search. However I was hoping for the simpler suggestion immediately on typing the name of the program.

As per discussions, the functionality is provided by the package command-not-found. However even after installing it, and also installing bash-completion package, this isn't available on the Debian bash shell.

23

The reason that installing command-not-found did not start providing suggestions for non-installed packages was that I had missed a small notification from dpkg as part of the install.

One is supposed to run the command update-command-not-found immediately after running apt-get install command-not-found. In fact dpkg prompts for running this command.

|improve this answer|||||
  • 2
    I also had to run apt-get update before running update-command-not-found then either open a new bash session or source /etc/bash.bash.rc. – jordanbtucker Feb 20 '19 at 16:53
  • I did an apt update before apt install command-not-found then the update-command-not-found, and then started a new shell, but found I needed another apt update and maybe update-command-not-found before it started working. – Dave X Apr 11 '19 at 3:22
9

The debian package seems to be incomplete. The README says that you should source /etc/bash_command_not_found in your .bashrc. Strangely that file is not included in the package.

The debian command-not-found package is based on the ubuntu package. The ubuntu package seems to be more complete in that regard.

Content of the ubuntu version of bash_command_not_found:

command_not_found_handle() {
  if  [ -x /usr/lib/command-not-found ]; then
     /usr/lib/command-not-found -- "$1" 
     return $?
  else
     return 127
  fi        
}

Add those lines to your ~/.bashrc (or /etc/bash.bashrc) and the command-not-found feature should work.

|improve this answer|||||
  • 1
    The README is incorrect, Debian does not use that file. The handler is included in /etc/bash.bashrc (at least in Debian 9) which is run automatically by Bash interactive shells when they start up. – hackerb9 Sep 11 '17 at 2:08
  • Installing the command-not-found package (version 0.2.38-4 from debian.org) to MX Linux (Debian 9 Stretch base) did not modify /etc/bash.bashrc and subsequently didn't work until adding the lines in this answer. – Xen2050 Sep 20 '18 at 11:52
0

I solve this problem by:

First install command-not-found

sudo apt update
sudo apt install command-not-found

After that

sudo update-command-not-found
sudo apt update
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.