Introduction to apt-cache command
apt-cache is an APT package handling tool that can be used for searching packages and packages names. apt-cache command searches and displays available information about installed and installable packages on Debian and Debian-based Linux systems. It is also helpful for keeping track of APT packages dependencies.
apt-cache command syntax
apt-cache uses /etc/apt/sources.list
file to fetch the information about packages.
The basic syntax for the apt-cache
command is:
$ apt-cache [option] command package_name
Some of the most used options are:
- -p, --pkg-cache Select the file to store the package cache. The package cache is the primary cache used by all operations.
- -s, --src-cache Select the file to store the source cache.
- -q, --quiet Quiet.
- -i, --important Print only important dependencies
- -f, --full Print full package records when searching.
- -g, --generate Perform automatic package cache regeneration, rather than use the cache as it is.
- -n, --names-only Only search on the package names, not the long descriptions.
- --all-names Make pkgnames print all names, including virtual packages and missing dependencies.
- --recurse Make depends recursive so that all packages mentioned are printed once
Different examples to use apt-cache command
1. apt-cache command to list all packages in the system
You can list the names of all packages in the system using the following command.
$ apt-cache pkgnames
Sample Output:
unity-scope-tomboy libgcc-10-dev-mips64r6-cross fcoe-utils calligra-data librust-clap+strsim-dev libmodule-pluggable-perl libgd-gd2-noxpm-ocaml-dev libappstreamqt-dev libtk-objscanner-perl dpuser ruby-nenv python-x2go-doc ...
You can use --all-names
option with pkgnames
command to print all names, including virtual packages and missing dependencies.
$ apt-cache --all-names pkgnames
2. apt-cache command to display information about the packages
The showpkg
command displays information about the packages given on the command line. It prints the available versions and reverse dependencies of the specified packages, and forward dependencies for each version.
You can specify multiple packages, but the package name must be valid.
$ apt-cache showpkg package_name
Sample Output:
golinux@ubuntu-PC:~$ apt-cache showpkg gcc Package: gcc Versions: 4:9.3.0-1ubuntu2 (/var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_main_binary-amd64_Packages) (/var/lib/dpkg/status) Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_main_binary-amd64_Packages MD5: c7efd71c7c651a9ac8b2adf36b137790 Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_main_binary-i386_Packages MD5: c7efd71c7c651a9ac8b2adf36b137790 Description Language: en File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_main_i18n_Translation-en MD5: c7efd71c7c651a9ac8b2adf36b137790 Reverse Depends: nodeenv,gcc 4:4.9.1 valac,gcc scilab-cli,gcc rustc,gcc linux-ibm-source-5.4.0,gcc golang-1.16-go,gcc gcc-10-doc,gcc 2.7.2.3-4.3 dahdi-dkms,gcc cargo,gcc sa-compile,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc linux-source-5.4.0,gcc ... Dependencies: 4:9.3.0-1ubuntu2 - cpp (5 4:9.3.0-1ubuntu2) gcc-9 (2 9.3.0-3~) gcc-doc (3 1:2.95.3) libc6-dev (16 (null)) libc-dev (0 (null)) gcc-multilib (0 (null)) make (0 (null)) manpages-dev (0 (null)) autoconf (0 (null)) automake (0 (null)) libtool (0 (null)) flex (0 (null)) bison (0 (null)) gdb (0 (null)) gcc-doc (0 (null)) gcc-doc:i386 (3 1:2.95.3) gcc:i386 (32 (null)) Provides: 4:9.3.0-1ubuntu2 - gcc:amd64 (= 4:9.3.0-1ubuntu2) gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2) c-compiler (= ) Reverse Provides:
3. apt-cache command to search the package lists
The search
command is mostly used command with apt-cache. It helps to search all available package lists for a regex pattern. It prints out the package name with a short description.
$ apt-cache search regex
Sample Output:
The search command searches the package names and the long description of packages. You can search only on the package names using -n
or --names-only
option.
$ apt-cache --names-only search regex
4. apt-cache command to display full package records when searching
When you use -f
or --full
option with search
command, it prints out the full package records for each matched package.
$ apt-cache -f search regex
OR
$ apt-cache --full search regex
Sample Output:
golinux@ubuntu-PC:~$ apt-cache --full search mysql Package: cvm-mysql Architecture: amd64 Version: 0.97-0.1build2 Priority: optional Section: universe/admin Source: cvm Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Gerrit Pape <pape@smarden.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 102 Depends: libbg2 (>= 2.03+dfsg-2), libc6 (>= 2.4), libcvm1, libmysqlclient21 (>= 8.0.11) Recommends: cvm Filename: pool/universe/c/cvm/cvm-mysql_0.97-0.1build2_amd64.deb Size: 8264 MD5sum: ab17f3140f23129cb456563ff379945d SHA1: a8bd60d54735e829c8525b45d559099a69cd4309 SHA256: f845e78c5dc9f8d6c3e0181021d84951d8ef05cd9e1794e5f25de104e4f853c3 Description-en: Credential Validation Modules (MySQL) CVM is a framework for validating a set of credentials against a database using a filter program. The modules act as a filter, taking a set of credentials as input and writing a set of facts as output if those credentials are valid. Optional input is given to the module through environment variables. . Some of the ideas for CVM came from experience with PAM (pluggable authentication modules), the checkpassword interface used by qmail-pop3d, and the "authmod" interface used by Courier IMAP and POP3. This framework places fewer restrictions on the invoking client than checkpassword does, and is much simpler to implement on both sides than PAM and the authmod framework. . See http://untroubled.org/cvm/cvm.html for more information. Description-md5: b19da2aba9378469365a5501c829b6eb
5. apt-cache command to show the package records
The show
command displays a readable record for the specified package.
$ apt-cache show package_name
Sample Output:
6. apt-cache command to show source package records
The showsrc
command displays all the source package records that match the given package names. All versions are shown, including all records declaring the name a Binary.
$ apt-cache showsrc package_name
Sample Output:
golinux@ubuntu-PC:~$ apt-cache showsrc nmap Package: nmap Format: 3.0 (quilt) Binary: nmap, nmap-common, ndiff, ncat Architecture: any all Version: 7.80+dfsg1-2build1 Priority: optional Section: universe/net Maintainer: Debian Security Tools <team+pkg-security@tracker.debian.org> Uploaders: Hilko Bengen <bengen@debian.org>, Samuel Henrique <samueloph@debian.org> Standards-Version: 4.4.0 Build-Depends: bison, debhelper (>= 12~), dh-python, flex, liblinear-dev, liblua5.3-dev, libpcap0.8-dev, libpcre3-dev, libssh2-1-dev, libssl-dev, zlib1g-dev, lua-lpeg-dev, python3 Build-Depends-Indep: default-jdk-headless, gcc-mingw-w64-i686 Homepage: https://nmap.org/ Vcs-Browser: https://salsa.debian.org/pkg-security-team/nmap Vcs-Git: https://salsa.debian.org/pkg-security-team/nmap.git Directory: pool/universe/n/nmap Package-List: ncat deb net optional arch=any ndiff deb net optional arch=all nmap deb net optional arch=any nmap-common deb net optional arch=all Files: 5a2e3f5e87baece81500d7a5e4fbdc36 2319 nmap_7.80+dfsg1-2build1.dsc a1710b69732897224ccc84ac53b1550a 7776928 nmap_7.80+dfsg1.orig.tar.xz a9907d50521d55dd5117cf07d9c8ec8a 33604 nmap_7.80+dfsg1-2build1.debian.tar.xz Checksums-Sha1: 46b8e1461d3685c9836e5acb17e7a164a74b7071 2319 nmap_7.80+dfsg1-2build1.dsc a268cef9b1cda2bb3b836de029f7b03cff5f73fe 7776928 nmap_7.80+dfsg1.orig.tar.xz d7195456f747caf9d5b2c668fc867592fb2d97b5 33604 nmap_7.80+dfsg1-2build1.debian.tar.xz Checksums-Sha256: 052f4dd13fb9f89f4bbe7fca42cd486e019993060b48202407c6ff4e8c5bf690 2319 nmap_7.80+dfsg1-2build1.dsc fac6950c683ed72c2c2f100aa91e3bb0f6634bf4394e77841e55a4eb2ccd7d66 7776928 nmap_7.80+dfsg1.orig.tar.xz 9ff5daae7705f82602b19f85aed329fa15b3d2c5b281d9c625eee2046a59e64e 33604 nmap_7.80+dfsg1-2build1.debian.tar.xz
7. Show raw dependency information for a package with apt-cache command
The depends
command helps to display a list of each dependency a package has and all other possible packages that can fulfill that dependency.
$ apt-cache depends package_name
Sample Output:
8. Show reverse dependency information for a package with apt-cache command
You can use rdepends
command to list reverse dependencies for a specified package.
$ apt-cache rdepends package_name
Sample Output:
9. apt-cache command to limit the output of depends and rdepends
By default, the depends
and rdepends
command print all dependencies for a package. You can use the following flags to not display the specified type of dependency.
--no-pre-depends --no-depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances
For example, to hide the suggested dependencies, you can use the command below:
$ apt-cache --no-suggests depends package_name
Sample Output:
10. apt-cache command to make depends and rdepends recursive
The --recurse
option makes depends
and rdepends
recursive so that all packages mentioned are printed once.
$ apt-cache --recurse depends package_name
Sample Output:
$ apt-cache --recurse depends openssh-client Depends: linux-objects-nvidia-390-5.13.0-1022-oem Depends: nvidia-kernel-common-390 Depends: nvidia-kernel-common-390 linux-modules-nvidia-390-5.11.0-1022-oracle |Depends: debconf Depends: <debconf-2.0> cdebconf debconf |Depends: linux-image-5.11.0-1022-oracle Depends: linux-image-unsigned-5.11.0-1022-oracle Depends: linux-signatures-nvidia-5.11.0-1022-oracle Depends: linux-objects-nvidia-390-5.11.0-1022-oracle Depends: nvidia-kernel-common-390 Depends: nvidia-kernel-common-390 linux-modules-nvidia-390-5.4.0-1058-oracle |Depends: debconf Depends: <debconf-2.0> cdebconf debconf |Depends: linux-image-5.4.0-1058-oracle Depends: linux-image-unsigned-5.4.0-1058-oracle Depends: linux-signatures-nvidia-5.4.0-1058-oracle Depends: linux-objects-nvidia-390-5.4.0-1058-oracle Depends: nvidia-kernel-common-390 Depends: nvidia-kernel-common-390
11. Limit the output of depends and rdepends
The --installed
option helps to limit the output of depends
and rdepends
command by showing the dependencies of the given package that are currently installed.
$ apt-cache --installed rdepends package_name
Sample Output:
12. apt-cache command to show policy settings
The policy
command prints out the priorities of each source. It helps to debug issues relating to the preferences file.
$ apt-cache policy [package_name]
Sample Output:
When a package name is specified, it prints out detailed information about the priority selection of the package.
golinux@ubuntu-PC:~$ apt-cache policy gcc gcc: Installed: 4:9.3.0-1ubuntu2 Candidate: 4:9.3.0-1ubuntu2 Version table: *** 4:9.3.0-1ubuntu2 500 500 http://np.archive.ubuntu.com/ubuntu focal/main amd64 Packages 100 /var/lib/dpkg/status
13. apt-cache command to display statistics about the cache
The stats
command displays some statistics about the cache.
$ apt-cache stats
Sample Output:
14. Show a list of every package in the cache with apt-cache command
The dump
command displays a short listing of every package in the cache. It is mainly used for debugging.
$ apt-cache dump
Sample Output:
golinux@ubuntu-PC:~$ apt-cache dump Package: gccgo-9-doc:i386 Package: libstdc++6-mips64r6-cross Version: 10.3.0-1ubuntu1~20.04cross1 File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal-updates_universe_binary-amd64_Packages Depends: gcc-10-cross-base-mipsen 10.3.0-1ubuntu1~20.04cross1 Depends: libc6-mips64r6-cross 2.30 Depends: libgcc-s1-mips64r6-cross 4.2 Depends: scim 1.4.2-1 Depends: scim:i386 1.4.2-1 Depends: libstdc++6-10-dbg-mips64r6-cross 4.9.0-3 Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_universe_binary-amd64_Packages MD5: 1415ddd4684985d7796518a5bbdae431 Description Language: en File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_universe_i18n_Translation-en MD5: 1415ddd4684985d7796518a5bbdae431 Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal-updates_universe_binary-amd64_Packages MD5: 1415ddd4684985d7796518a5bbdae431 Version: 10-20200324-1ubuntu1cross1 File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_universe_binary-amd64_Packages Depends: gcc-10-cross-base-mipsen 10-20200324-1ubuntu1cross1 Depends: libc6-mips64r6-cross 2.30 Depends: libgcc-s1-mips64r6-cross 4.2 Depends: scim 1.4.2-1 Depends: libstdc++6-10-dbg-mips64r6-cross 4.9.0-3 Depends: scim:i386 1.4.2-1 Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_universe_binary-amd64_Packages MD5: 1415ddd4684985d7796518a5bbdae431 Description Language: en File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal_universe_i18n_Translation-en MD5: 1415ddd4684985d7796518a5bbdae431 Description Language: File: /var/lib/apt/lists/np.archive.ubuntu.com_ubuntu_dists_focal-updates_universe_binary-amd64_Packages MD5: 1415ddd4684985d7796518a5bbdae431
15. apt-cache command to show an available list to stdout
You can use dumpavail
to print the available list of packages in the cache to stdout.
$ apt-cache dumpavail
Sample Output:
golinux@ubuntu-PC:~$ apt-cache dumpavail Package: python3-sanlock Architecture: amd64 Version: 3.8.2-2~ubuntu20.04.1 Priority: optional Section: universe/python Source: sanlock Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: HÃ¥vard Flaget Aasen <haavard_aasen@yahoo.no> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 67 Provides: python3.8-sanlock Depends: python3 (<< 3.9), python3 (>= 3.8~), libc6 (>= 2.4), libsanlock1 (= 3.8.2-2~ubuntu20.04.1) Filename: pool/universe/s/sanlock/python3-sanlock_3.8.2-2~ubuntu20.04.1_amd64.deb Size: 15592 MD5sum: acfac51b90e4ee677d503224a5a5f3d4 SHA1: 38cd8ac785419b6c4e29168cdc6aefc93686f9af SHA256: b680b7a96562352fbc64698a45fba434bb3e1b3d1a4d34ebfbf3a7c26cd7962f SHA512: 729f18b1143fe3dddbb7f39bf37be616db76fb87df7192fe2fe51ecf4f5c403124beefc46ed997c11e0da887b77bd947f90098d5b5aa1363e052d3ed3268735d Homepage: https://www.pagure.io/sanlock/ Description: Python3 bindings to shared storage lock manager Description-md5: 3ff9deb2a582537122b5a6bd7bf8848b
16. Display all unmet dependencies in the package cache with apt-cache comamnd
The unmet
command prints the summary of all unmet dependencies in the package cache.
$ apt-cache unmet
Sample Output:
golinux@ubuntu-PC:~$ apt-cache unmet Package libreoffice-l10n-en-za version 1:6.4.2-0ubuntu3 has an unmet dep: Suggests: libreoffice-help-en-za Suggests: mythes-en-za Package gdc-10-arm-linux-gnueabihf:i386 version 10.3.0-1ubuntu1~20.04cross1 has an unmet dep: Depends: libgphobos-10-dev-armhf-cross:i386 (>= 10) Package gdc-10-arm-linux-gnueabihf:i386 version 10-20200411-0ubuntu1cross1 has an unmet dep: Depends: libgphobos-10-dev-armhf-cross:i386 (>= 10) Package python3-paste version 3.4.0+dfsg1-1 has an unmet dep: Suggests: libapache2-mod-scgi Package tempest-for-eliza version 1.0.5-2.1build1 has an unmet dep: Suggests: xvidtune Package ddskk version 16.3-1 has an unmet dep: Suggests: eieio Package indent:i386 version 2.2.12-1 has an unmet dep: Suggests: indent-doc:i386 Package libomp-11-dev:i386 version 1:11.0.0-2~ubuntu20.04.1 has an unmet dep: Suggests: libomp-11-doc:i386 Package elpa-xml-rpc version 1.6.12-3 has an unmet dep: Enhances: emacs24 Enhances: emacs25
17. apt-cache command to print only important dependencies with unmet
The -i
or --important
option is used with unmet
command to print only important unmet dependencies in the package cache.
$ apt-cache unmet -i
OR
$ apt-cache unmet --important
Sample Output:
golinux@ubuntu-PC:~$ apt-cache -i unmet Package g++-10-multilib-powerpc-linux-gnu:i386 version 10.3.0-1ubuntu1~20.04cross1 has an unmet dep: Depends: lib64stdc++-10-dev-powerpc-cross:i386 (>= 10.3.0-1ubuntu1~20.04cross1) Package g++-10-multilib-powerpc-linux-gnu:i386 version 10-20200411-0ubuntu1cross1 has an unmet dep: Depends: lib64stdc++-10-dev-powerpc-cross:i386 (>= 10-20200411-0ubuntu1cross1) Package linux-modules-nvidia-470-5.8.0-63-generic version 5.8.0-63.71~20.04.1 has an unmet dep: Depends: nvidia-kernel-common-470 (<= 470.57.02-1) Package lvm2-dbusd:i386 version 2.03.07-1ubuntu1 has an unmet dep: Depends: python3-pyudev:i386 Package linux-modules-nvidia-450-server-5.11.0-27-generic version 5.11.0-27.29~20.04.1 has an unmet dep: Depends: nvidia-kernel-common-450-server (<= 450.142.00-1) Package linux-modules-nvidia-470-5.4.0-1059-aws version 5.4.0-1059.62+1 has an unmet dep: Depends: nvidia-kernel-common-470 (<= 470.82.00-1) Package linux-modules-nvidia-450-server-5.4.0-80-lowlatency version 5.4.0-80.90+2 has an unmet dep: Depends: nvidia-kernel-common-450-server (<= 450.142.00-1) Package gnat-9-x86-64-linux-gnu:i386 version 9.3.0-17ubuntu1~20.04cross2 has an unmet dep: Depends: libgnat-9-amd64-cross:i386 (>= 9.3.0-17ubuntu1~20.04cross2) Package gnat-9-x86-64-linux-gnu:i386 version 9.3.0-10ubuntu1cross2 has an unmet dep: Depends: libgnat-9-amd64-cross:i386 (>= 9.3.0-10ubuntu1cross2) Package g++-9-m68k-linux-gnu:i386 version 9.3.0-17ubuntu1~20.04cross1 has an unmet dep: Depends: libstdc++-9-dev-m68k-cross:i386 (>= 8) Package g++-9-m68k-linux-gnu:i386 version 9.3.0-10ubuntu1cross1 has an unmet dep: Depends: libstdc++-9-dev-m68k-cross:i386 (>= 8)
Conclusion
apt-cache
is a useful command to search for package names and descriptions. It also helps to get the information of all dependencies for a package. If you still have any confusion, please let us know in the comment section. For further information, you can visit the man page of apt-cache from the link given below.
What's Next
15 apt command practical examples in Linux [Cheat Sheet]
Further Reading
man page for apt-cache command
Hello,
I run apt-cache unmet on my system and I got some output. It seems to me that the unmet dependencies are lots. Is it danger for my system ? Is there anything I can do for solving it if this is a problem ?
Thank you for your kind attention
Best regards
Filippo