25

Sometimes you run a command and get a "command not found" error message.

After that you try to install the package that contains that command (I think that's what happens anyway?)

e.g. showmount: command not found

apt-get install showmount does nothing, so I guess the showmount command is part of a package, but I don't know what that package is.

How can I find out what package I need to install to get whichever command I need? I am using Kali Linux.

13

You can use apt-cache, which is included as default on debian based distributions (afaik):

apt-cache search showmount

which gives the result nfs-common as well.

  • 2
    That works in this case (and is a good idea anyway), but it only finds words mentioned in a package’s name and description, so it’s unfortunately not applicable generally. – Stephen Kitt Mar 31 '17 at 12:39
  • 1
    In Debian can work also like apt search pkgname – George Vasiliou Mar 31 '17 at 12:41
  • @StephenKitt Correct! – Joakim Mar 31 '17 at 14:26
  • both apt-cache search showmount and apt search showmount have me the result i was looking for. @StephenKitt when i use apt-file search showmount it says update cache despite already running apt-file update. That is why i have asked Joakims answer. – a.smith Apr 3 '17 at 8:47
  • That’s fine, I hope you don’t mind that I edited your question to make its title more specific as a result (since the accepted answer doesn’t work in general). – Stephen Kitt Apr 3 '17 at 9:03
28

You can use apt-file for that (you might need to install it):

apt-file search showmount

This reveals that the command is in the nfs-common package.

Typically when you're looking for a binary you can restrict the search by prefixing the binary with bin/:

apt-file search bin/showmount

To install apt-file, run

sudo apt-get install apt-file
sudo apt-file update

If you end up with apt-file 3.0 or later, you won’t need to update the indexes again separately (after the initial download above), they are updated whenever the main APT indexes are updated.

  • 2
    How do I figure out which package provides apt-file? :-) – Mark Mar 31 '17 at 22:18
  • @Mark - Don't know, but I do know it's its own package apt-file and for ubuntu, it's in the universe repo. – Joe Apr 1 '17 at 4:15
  • Before you use apt-file search, you should run sudo apt-file update - if you haven't done so recently. That updates all its indexes so it can find things based on your current set of repositories that apt knows about. It's separate from the update that sudo apt-get update does. – Joe Apr 1 '17 at 4:20
  • That is indeed a bit of a catch-22, I’ve updated my answer. – Stephen Kitt Apr 1 '17 at 6:33
17

You might want to ease your life by installing the command-not-found helper

$ sudo apt install command-not-found
[…]
$ showmount
Command 'showmount' is available in '/sbin/showmount'
The command could not be located because '/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative priviledges associated with your user account.
showmount: command not found
  • Nice, but note that this works in bash but not in other shells (I tried tcsh and zsh) – arielf Apr 3 '17 at 19:05
1

Browse over to http://packages.debian.org or http://packages.ubuntu.com under the 'Search the contents of packages' section. You can find the package that contains the file you need without installing other apt tools.

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.