Cyberithub

14 Useful APT CACHE Examples on Ubuntu 18.04

Advertisements

In this article, I will take you through 14 Useful apt cache examples on Ubuntu 18.04. APT CACHE allows you to search for packages and dependencies. It perform low-level operations on the APT binary cache, including the ability to perform searches and produce output reports from package metadata. It is very useful for finding out information about packages.

apt-get and apt are another utility to perform package, upgrade, update, removal etc on Ubuntu. To know more about apt-get, you can go to 20 Useful APT GET Examples on Ubuntu 18.04.

Prerequisites

a)You need to have a running Ubuntu 18.04 System.

b)You need to run all the commands through a User having sudo access. In this article, I have used test User. You can check How to Add User into Sudoers to provide sudo access to Users.

14 Useful APT CACHE Examples on Ubuntu 18.04 1

APT CACHE Examples

Also Read: How to Install NVM for Node.js on Ubuntu 18.04

1. Check APT CACHE Version

If you want to check apt cache version, then you need to run sudo apt-cache -v and check that.

test@localhost:~$ sudo apt-cache -v
apt 1.6.11 (amd64)

2. Show Package Information Using APT CACHE SHOWPKG

If you want to see all the package information say apache2 in this case, then you need to check it by running sudo apt-cache showpkg apache2 command. In the output you can notice package information like Versions, description are included.

test@localhost:~$ sudo apt-cache showpkg apache2
Package: apache2
Versions:
2.4.29-1ubuntu4.11 (/var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_bionic-updates_main_binary-amd64_Packages) (/var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_bionic-security_main_binary-amd64_Packages) (/var/lib/dpkg/status)
Description Language:
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_bionic_main_binary-amd64_Packages
MD5: d02426bc360345e5acd45367716dc35c
Description Language:

Reverse Depends:
apache2-dbg,apache2 2.4.29-1ubuntu4.11
nova-placement-api,apache2
squid-cgi,apache2
phpliteadmin,apache2 2.4.6-4~
ntpsec-ntpviz,apache2 2.4.6-4~
nova-placement-api,apache2
live-build-cgi,apache2

3. Check Package Stats Using APT CACHE STATS

If you want to display the Cache statistics, then you need to run sudo apt-cache stats command to check that.

test@localhost:~$ sudo apt-cache stats
Total package names: 84063 (1,681 k)
Total package structures: 126035 (5,546 k)
Normal packages: 90737
Pure virtual packages: 2563
Single virtual packages: 10326
Mixed virtual packages: 5104
Missing: 17305
Total distinct versions: 111679 (8,934 k)
Total distinct descriptions: 178239 (4,278 k)
Total dependencies: 882493/258114 (21.8 M)
Total ver/file relations: 35260 (846 k)
Total Desc/File relations: 47167 (1,132 k)
Total Provides mappings: 41759 (1,002 k)
Total globbed strings: 186787 (4,286 k)
Total slack space: 9,944
Total space accounted for: 49.9 M
Total buckets in PkgHashTable: 50503
Unused: 9467
Used: 41036
Utilization: 81.2546%
Average entries: 3.07133
Longest: 60
Shortest: 1

4. Dump all Package Information Using APT CACHE DUMP

If you want to simply list all the packages in Cache, then you can run sudo apt-cache dump command and list it. This command is generally used for debugging purposes.

test@localhost:~$ sudo apt-cache dump
Using Versioning System: Standard .deb
Package: libdatrie-doc
Version: 0.2.10-7
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_bionic_main_binary-amd64_Packages
Depends: libjs-jquery (null)
Depends: iceweasel (null)
Depends: www-browser (null)
Description Language:
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_bionic_main_binary-amd64_Packages
MD5: 007ed6dfc7f608119b6b8b018056fc70
Description Language: en
File: /var/lib/apt/lists/in.archive.ubuntu.com_ubuntu_dists_bionic_main_i18n_Translation-en
MD5: 007ed6dfc7f608119b6b8b018056fc70

5. Dump all Package Information Using APT CACHE

If you want to dump all the packages to standard output, then you need to use dumpavail option with apt cache to do that as shown below.

test@localhost:~$ sudo apt-cache dumpavail
Package: accountsservice
Architecture: amd64
Version: 0.6.45-1ubuntu1
Priority: standard
Section: gnome
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian freedesktop.org maintainers <pkg-freedesktop-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 440
Depends: dbus, libaccountsservice0 (= 0.6.45-1ubuntu1), libc6 (>= 2.4), libglib2.0-0 (>= 2.37.3), libpolkit-gobject-1-0 (>= 0.99)
Suggests: gnome-control-center
Filename: pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb
Size: 62000
MD5sum: c2cffd1eb66b6392f350b474e583adba
SHA1: 71d89bd380a465397b42ea3031afa53eaf91661a
SHA256: d0b11d1d27fe425bc91ea51fab74ad45e428753796f0392e446e8b2450293255
Homepage: https://www.freedesktop.org/wiki/Software/AccountsService/
Description: query and manipulate user account information
Task: standard
Description-md5: 8aeed0a03c7cd494f0c4b8d977483d7e
Supported: 5y

6. Display Summary of all Unmet Dependencies 

If you want to display summary of all unmet dependencies in package cache, then you need to use unmet option with apt cache command as shown below.

test@localhost:~$ sudo apt-cache unmet
Package kde-baseapps-bin:i386 version 4:16.04.3-0ubuntu1 has an unmet dep:
Depends: kde-baseapps-data:i386 (= 4:16.04.3-0ubuntu1)
Package libghc-gtk-dev:i386 version 0.14.7-1build2 has an unmet dep:
Suggests: libghc-gtk-doc:i386
Package openmsx:i386 version 0.14.0-2 has an unmet dep:
Depends: openmsx-data:i386 (= 0.14.0-2)
Depends: cbios:i386 (>= 0.23)
Package gobjc-8-multilib-powerpc64-linux-gnu:i386 version 8.3.0-6ubuntu1~18.04.1cross1 has an unmet dep:
Depends: lib32objc-8-dev-ppc64-cross:i386 (>= 8.3.0-6ubuntu1~18.04.1cross1)
Package gobjc-8-multilib-powerpc64-linux-gnu:i386 version 8-20180414-1ubuntu2cross1 has an unmet dep:
Depends: lib32objc-8-dev-ppc64-cross:i386 (>= 8-20180414-1ubuntu2cross1)
Package node-almond:i386 version 0.3.3+dfsg-1 has an unmet dep:
Depends: node-requirejs-text:i386
Package multimedia-recording version 0.6ubuntu2 has an unmet dep:
Recommends: ardour3
Suggests: beast
Suggests: composite
Suggests: jack-oscrolloscope
Suggests: jokosher
Suggests: non-mixer
Suggests: rezound

7. Search a Package

If you want to search a package say apache2 in this case, then you need to run sudo apt-cache search apache2 command to do that.

test@localhost:~$ sudo apt-cache search apache2
apache2 - Apache HTTP Server
apache2-bin - Apache HTTP Server (modules and other binary files)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)
apache2-doc - Apache HTTP Server (on-site documentation)
apache2-ssl-dev - Apache HTTP Server (mod_ssl development headers)

8. Check Reverse Dependency of a Package

If you want to check reverse dependency of a package say apache2 in this case, then you need to use sudo apt-cache rdepends apache2 command.

test@localhost:~$ sudo apt-cache rdepends apache2
apache2
Reverse Depends:
apache2-dbg
|nova-placement-api
|squid-cgi
|phpliteadmin
|ntpsec-ntpviz
|nova-placement-api
|live-build-cgi
|libopenjpip-server
|gnocchi-api

9. List all Dependency of a Package

If you want to list all the dependencies of a package say apache2 in this case, then you need to execute sudo apt-cache depends apache2 command.

test@localhost:~$ sudo apt-cache depends apache2
apache2
PreDepends: dpkg
dpkg:i386
Depends: lsb-base
Depends: procps
procps:i386
Depends: perl
Depends: mime-support
Depends: apache2-bin
Depends: apache2-utils
apache2-utils:i386

10. Display all packages

If you want to display all the packages in your System, then you need to use sudo apt-cache pkgnames command as shown below.

test@localhost:~$ sudo apt-cache pkgnames
libdatrie-doc
libfstrcmp0-dbg
libghc-monadplus-doc
librime-data-sampheng
python-pyao-dbg
fonts-georgewilliams
python3-aptdaemon.test
libcollada2gltfconvert-dev
python3-doc8
r-bioc-hypergraph

11. Check Policy of a Package Using APT CACHE POLICY

If you want to check the detailed information about the priority selection of a specified package say apache2 in this case, you can check that by using sudo apt-cache policy apache2 command as shown below.

test@localhost:~$ sudo apt-cache policy apache2
apache2:
Installed: 2.4.29-1ubuntu4.11
Candidate: 2.4.29-1ubuntu4.11
Version table:
*** 2.4.29-1ubuntu4.11 500
500 http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
100 /var/lib/dpkg/status
2.4.29-1ubuntu4 500
500 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

12. Show Available version of a Package in Madison Format

If you to see all available version of a package in madison format, you can check it running sudo apt-cache madison apache2 command.

test@localhost:~$ sudo apt-cache madison apache2
apache2 | 2.4.29-1ubuntu4.11 | http://in.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
apache2 | 2.4.29-1ubuntu4.11 | http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
apache2 | 2.4.29-1ubuntu4 | http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

13. Turn Off Automatic Cache Generation

If you want to turn off Automatic Cache Generation, you can do that by using --no-generate option apt cache.

test@localhost:~$ sudo apt-cache search apache2 --no-generate
apache2 - Apache HTTP Server
apache2-bin - Apache HTTP Server (modules and other binary files)
apache2-data - Apache HTTP Server (common files)
apache2-dbg - Apache debugging symbols
apache2-dev - Apache HTTP Server (development headers)
apache2-doc - Apache HTTP Server (on-site documentation)
apache2-ssl-dev - Apache HTTP Server (mod_ssl development headers)
apache2-utils - Apache HTTP Server (utility programs for web servers)
libapache2-mod-apparmor - changehat AppArmor library as an Apache module
libapache2-mod-auth-mellon - SAML 2.0 authentication module for Apache
libapache2-mod-auth-pgsql - Module for Apache2 which provides PostgreSQL authentication
libapache2-mod-auth-plain - Module for Apache2 which provides plaintext authentication

14. Check Other Options with --help

You can also the other options available with apt cache using --help option as shown below.

test@localhost:~$ apt-cache --help
apt 1.6.11 (amd64)
Usage: apt-cache [options] command
apt-cache [options] show pkg1 [pkg2 ...]

apt-cache queries and displays available information about installed
and installable packages. It works exclusively on the data acquired
into the local cache via the 'update' command of e.g. apt-get. The
displayed information may therefore be outdated if the last update was
too long ago, but in exchange apt-cache works independently of the
availability of the configured sources (e.g. offline).

Most used commands:
showsrc - Show source records
search - Search the package list for a regex pattern
depends - Show raw dependency information for a package

 

Also Read: 10+ lsyncd examples to sync directories real time in CentOS/RHEL 7

Reference: Linux in a Nut Shell

Leave a Comment