I am using a minimal Debian system which does not have the top program installed. I tried to install top with sudo apt-get install top, but top is not a package name.
It seems that top is a part of some other package. How can I find out which package I should install to get it? More generally, how can I find the package that contains a program?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The direct answer is procps. Here is how you can find this out for yourself:
# Install apt-file, which allows you to search # for the package containing a file sudo apt-get install apt-file # Update the package/file mapping database sudo apt-file update # Search for "top" at the end of a path apt-file search --regexp '/top$'
The output of the final command should look something like this:
crossfire-maps: /usr/share/games/crossfire/maps/santo_dominion/magara/well/top crossfire-maps-small: /usr/share/games/crossfire/maps/santo_dominion/magara/well/top liece: /usr/share/emacs/site-lisp/liece/styles/top lxpanel: /usr/share/lxpanel/profile/two_panels/panels/top procps: /usr/bin/top quilt: /usr/share/quilt/top
You can see that only procps provides an executable in your standard PATH, which gives a clue that it might be the right one. You can also find out more about procps to make sure like it seems like the right one:
$ apt-cache show procps Package: procps Version: 1:3.3.3-3 [...] Description-en: /proc file system utilities This package provides command line and full screen utilities for browsing procfs, a "pseudo" file system dynamically generated by the kernel to provide information about the status of entries in its process table (such as whether the process is running, stopped, or a "zombie"). . It contains free, kill, pkill, pgrep, pmap, ps, pwdx, skill, slabtop, snice, sysctl, tload, top, uptime, vmstat, w, and watch.
Method 2
You can search for things with apt-cache search ..., although it is just a match on package names and descriptions, which sometimes is not enough. In that case using, e.g.,
apt-file search top
might work — it finds all packages that have a file with top in their name, but for this that is a bit zany (it includes setopt, .desktop, etc). To refine this as per Chris’s answer:
apt-file search --regexp 'bin/top$'
This will find packages that have a file path ending (‘$’ is regular expression syntax signifying the end) in bin/top; executables are always in either a bin or sbin directory. When you find what you’re looking for:
apt-get install whatever
In this case whatever is apparently procps.
Method 3
apt-file search all repos listed in /etc/apt/sources.list and related databases, as long as repo serve a contents-%architecture%.gz.
if believe the file of interest is an executable name “top”, use this regex. ‘^/(usr/)?s?bin/top$’
for the official debian repo, there is a web interface https://packages.debian.org/file:top, there are other search options.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0