apt-cache

apt-cache command examples

Displaying Package Information with the apt-cache command


"apt-cache" is a command line driven utility for working with the APT (Advanced Package Tool). apt-cache is used mainly for the displaying of package information. The APT cache can be quickly searched using this handy tool.

apt-cache gencaches


"gencaches" performs the same operation as the "apt-get check" command. It builds the source and package caches from the sources in the sources.list




apt-cache showpkg


The "apt-cache showpkg" command displays information about packages listed on the command line. Dependencies and version details are displayed:



landoflinux@ubuntu1510:~$ sudo apt-cache showpkg htop
Package: htop
Versions: 
1.0.3-1 (/var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_wily_universe_binary-amd64_Packages)
 Description Language: 
                 File: /var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_wily_universe_binary-amd64_Packages
                  MD5: 8eb5aa19b3c92a975dc78e2165f6688d
 Description Language: en
                 File: /var/lib/apt/lists/gb.archive.ubuntu.com_ubuntu_dists_wily_universe_i18n_Translation-en
                  MD5: 8eb5aa19b3c92a975dc78e2165f6688d


Reverse Depends: 
  htop:i386,htop
  util-vserver,htop
  ubuntu-benchmark-tools,htop
  lava-dispatcher,htop
  hollywood,htop
Dependencies: 
1.0.3-1 - libc6 (2 2.15) libncursesw5 (2 5.6+20070908) libtinfo5 (0 (null)) strace (0 (null)) ltrace (0 (null)) htop:i386 (0 (null)) 
Provides: 
1.0.3-1 - 
Reverse Provides:

apt-cache stats


The "apt-cache stats" command provides some statistics about the cache.



landoflinux@ubuntu1510:~$ sudo apt-cache stats
Total package names: 65902 (1,318 k)
Total package structures: 110602 (6,194 k)
  Normal packages: 76284
  Pure virtual packages: 1332
  Single virtual packages: 9420
  Mixed virtual packages: 2015
  Missing: 21551
Total distinct versions: 80757 (5,815 k)
Total distinct descriptions: 102925 (2,470 k)
Total dependencies: 621918 (17.4 M)
Total ver/file relations: 84580 (2,030 k)
Total Desc/File relations: 102925 (2,470 k)
Total Provides mappings: 18127 (363 k)
Total globbed strings: 164 (2,129 )
Total dependency version space: 2,987 k
Total slack space: 54.5 k
Total space accounted for: 31.9 M

apt-cache dump


The "apt-cache dump" command is used to display a short listing of every package in the APT cache. The main use for this file is debugging purposes.


apt-cache dumpavail


The option "dumpavail" prints out an available list to stdout.


apt-cache unmet


The "apt-cache unmet" command displays a summary of all unmet dependencies in the PAT package cache.


apt-cache show


The "apt-cache show" command displays the package records for the specified package.



landoflinux@ubuntu1510:~$ sudo apt-cache show htop
Package: htop
Priority: optional
Section: universe/utils
Installed-Size: 198
Maintainer: Ubuntu Developers 
Original-Maintainer: Eugene V. Lyubimkin 
Architecture: amd64
Version: 1.0.3-1
Depends: libc6 (>= 2.15), libncursesw5 (>= 5.6+20070908), libtinfo5
Suggests: strace, ltrace
Filename: pool/universe/h/htop/htop_1.0.3-1_amd64.deb
Size: 65350
MD5sum: aa9dbc8d6c8a4f20a4828c32d59ce475
SHA1: 0173fbc0e16a55a112367eacda9a286aeab14d52
SHA256: 199fc6191c2b9a8b7b7e66559df15a9ac393217276dbc82373893660428d38ae
Description-en: interactive processes viewer
 Htop is an ncursed-based process viewer similar to top, but it
 allows one to scroll the list vertically and horizontally to see
 all processes and their full command lines.
 .
 Tasks related to processes (killing, renicing) can be done without
 entering their PIDs.
Description-md5: 8eb5aa19b3c92a975dc78e2165f6688d
Homepage: http://hisham.hm/htop/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

apt-cache search


"apt-cache search" provides a full search for all packages using a regular expression.



landoflinux@ubuntu1510:~$ sudo apt-cache search nrpe
nagios-nrpe-plugin - Nagios Remote Plugin Executor Plugin
nagios-nrpe-server - Nagios Remote Plugin Executor Server
nagios-plugins - Plugins for nagios compatible monitoring systems (metapackage)
nagios-plugins-basic - Plugins for nagios compatible monitoring systems
check-mk-agent - general purpose nagios-plugin for retrieving data
check-mk-agent-logwatch - general purpose nagios-plugin for retrieving data
check-mk-config-icinga - general purpose nagios-plugin for retrieving data
check-mk-config-nagios3 - general purpose nagios-plugin for retrieving data
check-mk-doc - general purpose nagios-plugin for retrieving data (documentation)
check-mk-livestatus - general purpose nagios-plugin for retrieving data
check-mk-multisite - general purpose nagios-plugin for retrieving data
check-mk-server - general purpose nagios-plugin for retrieving data
mcollective-plugins-nrpe - mcollective plugin for nagios nrpe
nagios-plugins-contrib - Plugins for nagios compatible monitoring systems
nagios-snmp-plugins - SNMP Plugins for nagios
shinken-mod-booster-nrpe - Shinken booster-nrpe module


apt-cache policy


"apt-cache policy" will display install information relating to the specified package. This command can be sued to show if a package is installed and at what version. It will also show if a newer version of the package is available.



landoflinux@ubuntu1510:~$ apt-cache policy htop
htop:
  Installed: (none)
  Candidate: 1.0.3-1
  Version table:
     1.0.3-1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages

From the above output we can see that the specified package is not installed on our system. This is indicated with "(none)" We can also see that it is available within the repositories for installation. If we were to install the package, the output would look similar to the output below:



landoflinux@ubuntu1510:~$ apt-cache policy htop
htop:
  Installed: 1.0.3-1
  Candidate: 1.0.3-1
  Version table:
 *** 1.0.3-1 0
        500 http://gb.archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages
        100 /var/lib/dpkg/status


From the above output we can now see that the package "htop" is installed and is at the latest version level


apt-cache depends


"apt-cache depends" shows a listing for each dependency a package has and all the possible other packages that can fulfil that dependency.



landoflinux@ubuntu1510:~$ apt-cache depends htop
htop
  Depends: libc6
  Depends: libncursesw5
  Depends: libtinfo5
  Suggests: strace
  Suggests: ltrace
  Conflicts: htop:i386

apt-cache rdepends


Displays a listing of each reverse dependency a package has.



landoflinux@ubuntu1510:~$ apt-cache rdepends htop
htop
Reverse Depends:
  htop:i386
  util-vserver
  ubuntu-benchmark-tools
  lava-dispatcher
  hollywood

apt-cache - help


For further options available to the apt-cache command, you can issue the command "apt-cache --help" or "man apt-cache":



landoflinux@ubuntu1510:~$ apt-cache --help
apt 1.0.10.2ubuntu1 for amd64 compiled on Oct  5 2015 15:55:05
Usage: apt-cache [options] command
       apt-cache [options] showpkg pkg1 [pkg2 ...]
       apt-cache [options] showsrc pkg1 [pkg2 ...]

apt-cache is a low-level tool used to query information
from APT's binary cache files

Commands:
   gencaches - Build both the package and source cache
   showpkg - Show some general information for a single package
   showsrc - Show source records
   stats - Show some basic statistics
   dump - Show the entire file in a terse form
   dumpavail - Print an available file to stdout
   unmet - Show unmet dependencies
   search - Search the package list for a regex pattern
   show - Show a readable record for the package
   depends - Show raw dependency information for a package
   rdepends - Show reverse dependency information for a package
   pkgnames - List the names of all packages in the system
   dotty - Generate package graphs for GraphViz
   xvcg - Generate package graphs for xvcg
   policy - Show policy settings

Options:
  -h   This help text.
  -p=? The package cache.
  -s=? The source cache.
  -q   Disable progress indicator.
  -i   Show only important deps for the unmet command.
  -c=? Read this configuration file
  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp
See the apt-cache(8) and apt.conf(5) manual pages for more information.