How to Use apt-cache Command in Ubuntu and Debian

In Debian-based distributions such as Ubuntu, package management plays a crucial role in installing, upgrading, and removing software packages.

One of the fundamental components of the package management system is APT (Advanced Package Tool), which includes various utilities for managing packages, one such utility called apt-cache, which is used for package searching, querying, and information retrieval.

What is apt-cache?

apt-cache is a command-line utility that allows users to interact with the package cache, which contains metadata, and information about available packages, including their names, descriptions, dependencies, and versions.

By utilizing apt-cache, users can quickly search for packages, retrieve package information, and perform other operations related to package management in Debian-based systems.

This article explores the usage of apt-cache with examples that will help you to keep track of software dependencies in your Linux system.

1. Search for Packages in Ubuntu

The apt-cache search command is used to search for packages in the package cache based on specific keywords in their names or descriptions.

For example, if you’re looking for a video player, you can use the following command, which will display a list of packages whose names or descriptions contain the specified keyword.

$ sudo apt-cache search video player
Search for Packages in Ubuntu
Search for Packages in Ubuntu

2. List Available Packages in Ubuntu

The apt-cache pkgnames command is used to retrieve a comprehensive list of package names without any descriptions or additional information from the package cache.

$ sudo apt-cache pkgnames

The above command will display a long list of package names. Since the list can be quite extensive, you may want to use tools like less or grep to navigate or filter the results.

For example, you can pipe the output to less to scroll through the list:

$ sudo apt-cache pkgnames | less
List Available Packages in Ubuntu
List Available Packages in Ubuntu

Alternatively, you can use grep to search for a specific package called Python as shown.

$ sudo apt-cache pkgnames | grep python
Search for Specific Packages
Search for Specific Packages

3. Find Details of a Package in Ubuntu

The apt-cache show command is used to display detailed information about a specific package such as description, version, dependencies, and other details from the system package cache.

For example, if you want to get the complete information about the package “apache2“, you can use:

$ sudo apt-cache show apache2
Check Package Info in Ubuntu
Check Package Info in Ubuntu

4. List Dependencies of a Package in Ubuntu

Use the ‘showpkg‘ sub-command to check the dependencies for particular software packages. whether those dependencies packages are installed or not.

For example, use the ‘showpkg‘ command along with package-name to get detailed information about version, dependencies, and reverse dependencies.

$ sudo apt-cache showpkg apache2
List Dependencies of a Package
List Dependencies of a Package

5. View Cache Statistics in Ubuntu

The ‘stats‘ sub-command will display overall statistics about the cache. For example, the following command will display a total number of packages found in the cache along with the disk space usage, and other relevant cache-related information.

$ sudo apt-cache stats
Show Statistics of Package Cache
Show Statistics of Package Cache

6. Check a Package Installation Status

The apt-cache policy command is used to print detailed information about the package installation status and available versions. It provides an overview of the candidate versions that can be installed, as well as the currently installed version, if applicable.

$ sudo apt-cache policy apache2
Check Package Installation Status
Check Package Installation Status
Conclusion

The apt-cache command offers essential functionality for searching, querying, and retrieving package information in Debian-based systems.

By leveraging the power of apt-cache, users can streamline the installation, upgrading, and removal of software packages, enhancing system stability and efficiency in the process.

Similar Posts