If you're a Linux user, especially on a Debian-based system like Ubuntu, you've probably heard of apt-get
and apt
. These are powerful tools for managing software packages. But did you know there's another command-line tool called apt-cache
that can help you query package information quickly and efficiently? In this brief tutorial, we'll discuss what apt-cache
is, how to use it to query package information in Debian, Ubuntu and its derivatives.
Table of Contents
What is apt-cache
?
apt-cache
is a command-line utility that allows you to query the package information stored in your system's package cache. This tool is useful for searching for packages, displaying detailed information about them, and understanding their dependencies. Unlike apt-get
, which is used for installing and removing packages, apt-cache
focuses on providing information about available packages.
Common apt-cache
Commands
Here are some of the most common apt-cache
commands you'll use:
1. Search for Packages
To search for packages that match a specific keyword, use the following command:
apt-cache search keyword
Example:
apt-cache search image editor
This command searches for packages that match to the keywords "image" and "editor" and lists them along with a brief description.
Sample Output:
fontforge - font editor fontforge-nox - font editor - non-X version gimp - GNU Image Manipulation Program libreoffice - office productivity suite (metapackage) android-platform-tools-base - base tools for developing applications for the Android system briquolo-data - data files for the fast paced 3d Breakout game Briquolo charactermanaj - avatar editor application chntpw - NT SAM password recovery utility copyq - Advanced clipboard manager with editing and scripting features copyq-plugins - Plugins for CopyQ digikam - digital photo management application for KDE showfoto - image viewer/editor for KDE drawing - simple drawing application for the GNOME desktop ephoto - Comprehensive Image Viewer Using EFL fim - scriptable frame buffer, X.org and ascii art image viewer [...]
2. Show Package Details
To display detailed information about a specific package, use the following command:
apt-cache show package_name
Example:
apt-cache show firefox-esr
This command shows detailed information about the Firefox browser, including its version, description, and more.
3. Show Package Dependencies
To see the dependencies of a specific package, use the following command:
apt-cache depends package_name
Example:
apt-cache depends linux-image-amd64
This command lists all the dependencies required by the linux-image-amd64
package.
Sample Output:
linux-image-amd64 Depends: linux-image-6.1.0-25-amd64
4. Show Package Installation Policy
To display the installation policy for a specific package, use the following command:
apt-cache policy package_name
Example:
apt-cache policy python3
This command shows the installation policy for Python 3, including the available versions and their priorities.
Sample Output:
python3: Installed: 3.11.2-1+b1 Candidate: 3.11.2-1+b1 Version table: *** 3.11.2-1+b1 500 500 http://deb.debian.org/debian bookworm/main amd64 Packages 100 /var/lib/dpkg/status
5. List All Package Names
To list all the package names available in your cache, use the following command:
apt-cache pkgnames
This command is useful if you want to see a comprehensive list of all packages available for installation.
6. Display Cache Statistics
To display statistics about your package cache, use the following command:
apt-cache stats
This command provides information about the number of packages, their sizes, and more.
Sample Output:
Total package names: 122971 (3,443 k) Total package structures: 109860 (4,834 k) Normal packages: 64508 Pure virtual packages: 1088 Single virtual packages: 34397 Mixed virtual packages: 448 Missing: 9419 Total distinct versions: 67184 (5,912 k) Total distinct descriptions: 131717 (3,161 k) Total dependencies: 412137/110983 (10.0 M) Total ver/file relations: 5497 (132 k) Total Desc/File relations: 645 (15.5 k) Total Provides mappings: 39988 (960 k) Total globbed strings: 221945 (5,173 k) Total slack space: 104 k Total space accounted for: 35.3 M Total buckets in PkgHashTable: 196613 Unused: 112576 Used: 84037 Utilization: 42.7423% Average entries: 1.30728 Longest: 17 Shortest: 1 Total buckets in GrpHashTable: 196613 Unused: 105223 Used: 91390 Utilization: 46.4822% Average entries: 1.34556 Longest: 7 Shortest: 1
Benefits of Using apt-cache
- Quick Package Searches:
apt-cache
allows you to quickly search for packages by keyword, making it easy to find the software you need. - Detailed Package Information: With
apt-cache
, you can access detailed information about any package, including its version, description, and more. - Dependency Resolution: Understanding a package's dependencies is crucial for troubleshooting and ensuring smooth installation.
apt-cache
makes it easy to view these dependencies.
Conclusion
apt-cache
is a useful tool for querying package information on Debian-based Linux systems. Whether you're searching for a specific package, looking for detailed information, or understanding dependencies, apt-cache
makes it easy.
So next time you need to find out more about a package, remember to use apt-cache
!