27

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.

ErebusBat
  • 935
  • 4
  • 12
  • 21

4 Answers4

24

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
EEAA
  • 109,363
  • 18
  • 175
  • 245
  • 1
    `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. – EEAA 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
  • 1
    @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
  • well, bummer i m in docker, `#apt-file update bash: apt-file: command not found` – ntg Jun 30 '21 at 10:27
  • but: `#apt-get install dnsutils ...............Fetched 603 kB in 0s (1461 kB/s) ....Unpacking ....done` – ntg Jun 30 '21 at 10:30
3

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.

Tobu
  • 4,437
  • 1
  • 24
  • 31
0

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.

Zoredache
  • 130,897
  • 41
  • 276
  • 420
0

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.

Dopamine
  • 176
  • 1
  • 8