As a concrete example I want to be able to take a particular tool that isn't installed (say nslookup) and be able to tell which package I need to install when the following fails:

apt-get install nslookup
E: Unable to locate package nslookup

Obviously I can google to find the answer for a specific package (dnsutils) but I want to know how to find it myself.

link|improve this question

this is quick and dirty apt-cache search nslookup – The Unix Janitor Nov 18 '10 at 23:34
apt-cache only searches the descriptions. I was looking for specific file, ErikA pointed out: apt-file search FOO – ErebusBat Nov 22 '10 at 15:01
feedback

4 Answers

up vote 3 down vote accepted

There are two ways I know of to do this:

host ~ # apt-file update
host ~ # apt-file search nslookup
dnsutils: /usr/bin/nslookup
dnsutils: /usr/share/man/man1/nslookup.1.gz
gajim: /usr/share/gajim/src/common/nslookup.py
kaptain: /usr/share/kaptain/nslookup.kaptn
kvirc2-data: /usr/share/kvirc2/help/en/nslookup.kvihelp
libgnet2.0-0: /usr/share/doc/libgnet2.0-0/examples/dnslookup.c.gz
manpages-ja: /usr/share/man/ja/man8/nslookup.8.gz
procmail-lib: /usr/share/procmail-lib/pm-janslookup.rc
rbot: /usr/share/rbot/plugins/nslookup.rb
scrollz: /usr/share/scrollz/help/nslookup
zsh: /usr/share/zsh/4.3.4/functions/Completion/Unix/_nslookup
zsh: /usr/share/zsh/4.3.4/functions/Misc/nslookup
zsh-beta: /usr/share/zsh-beta/functions/Completion/Unix/_nslookup
zsh-beta: /usr/share/zsh-beta/functions/Misc/nslookup

and...

host ~ # apt-cache search nslookup
host - utility for querying DNS servers
dnsutils - Clients provided with BIND
link|improve this answer
apt-cache only searches the packages you already have installed, while apt-file searches ALL packages in your sources.list, including packages that aren't installed. So in this case, apt-file is the one to use. – Steven Monday Nov 18 '10 at 23:15
1  
@Steven, I'm going to have to disagree with that. I just did a test search for "vlc" on my ubuntu VPS using apt-cache, and it showed all of the vlc-related packages, none of which I have installed. – ErikA Nov 18 '10 at 23:21
@Steven Monai, that isn't true. apt-cache looks at package descriptions (searches /var/lib/apt/lists/*_Packages). Having something installed doesn't matter. The package descriptions don't include a list of the files. I agree that apt-file is probably the tool to use, if opening a web browser isn't an option. – Zoredache Nov 18 '10 at 23:22
There's also auto-apt, as an alternative to apt-file. I don't have a strong preference. auto-apt can listen on failed exec calls, which can be useful when running a configure script that does feature detection. – Tobu Nov 18 '10 at 23:31
@EricA, Zoredache: I stand corrected. Let me restate: If you need to know which uninstalled package contains a particular file (e.g. /usr/bin/nslookup), then use apt-file. If you only want to search the package names and descriptions, then apt-cache works just fine. – Steven Monday Nov 18 '10 at 23:57
feedback

Do you have command-not-found installed?

Just type the command in bash or zsh and it will tell you which package has it, and if you need to enable non-main repos or fix your PATH. Or call command-not-found $command_name.

Or you could go to http://packages.ubuntu.com/file:bin/nslookup , but that defaults to karmic packages.

link|improve this answer
feedback

Do you need to do this from the command line? I usually just do a search on http://packages.ubuntu.com/ (or packages.debian.org) when I am looking for packages.

link|improve this answer
feedback

Ubuntu's online repository browser has "Search the contents of packages" feature. AFAIK, it's not implemented in apt-get/aptitude, but in the most cases you will be satisfied with "apt-get search" when searching for a package containing a similarly named program.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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