Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

mc

and it isnt 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 isnt available on the Debian bash shell.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment
up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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