Checking Package Versions Using apt-cache policy Command in Debian Systems

Nov 27, 2025 · Programming · 11 views · 7.8

Keywords: Debian | apt-cache | package version

Abstract: This article provides a comprehensive guide on using the apt-cache policy command to check package versions in Debian and its derivatives. Through practical examples, it demonstrates how to view installed and available versions, while comparing differences between tools like apt-get, apt-cache, and apt for version queries. Additional auxiliary commands such as apt-show and aptitude are also covered to help users master package version management techniques.

Importance of Package Version Queries

In Debian and its derivative systems like Ubuntu, package management is one of the core maintenance tasks. Understanding available version information before installing or upgrading packages is crucial. This not only helps avoid version conflicts but also ensures system stability and security. The traditional dpkg -l command only displays information about installed packages and cannot provide detailed information about available versions in repositories.

Detailed Explanation of apt-cache policy Command

The apt-cache policy <package name> command is the most direct and effective method for querying package version information. This command displays three key pieces of information: currently installed version, candidate installation version, and list of available versions. Taking the hylafax+ package as an example, executing apt-cache policy hylafax+ will output content similar to:

hylafax+:
  Installed: 5.5.3-1
  Candidate: 5.5.4-1
  Version table:
     5.5.4-1 500
        500 http://deb.debian.org/debian bullseye/main amd64 Packages
 *** 5.5.3-1 100
        100 /var/lib/dpkg/status

In the output, the "Installed" field shows the version currently installed on the system, "Candidate" indicates the version that will be installed by default, and "Version table" details all available versions along with their priorities.

Comparison with Other Version Query Methods

In addition to apt-cache policy, the system provides multiple version query tools:

apt show command: apt show <package> provides detailed package information including version, description, dependencies, etc. However, it's important to note that this command primarily displays candidate version information and is not as comprehensive as apt-cache policy.

Simulation installation: Using apt-get -s install <package> simulates the installation process, allowing you to view the specific version that will be installed in the output. This method is particularly useful for confirming the final installation version in complex dependency scenarios.

aptitude tool: For users who prefer graphical interfaces, aptitude provides interactive version query functionality. Using aptitude versions <package> in the command line also provides detailed version information.

Practical Application Scenarios

In actual system management, version queries are commonly used in the following scenarios:

Version upgrade decisions: By comparing current versions with available versions, decisions can be made about whether upgrades are necessary. For example, when security update versions are discovered, they should be promptly upgraded to fix vulnerabilities.

Dependency analysis: When installing new software, it's necessary to confirm version compatibility of dependency packages. apt-cache policy can help identify potential version conflicts.

Multiple repository management: When the system is configured with multiple software sources, different repositories may provide different versions of packages. apt-cache policy can clearly display versions provided by each repository and their priorities.

Best Practice Recommendations

To obtain accurate version information, it's recommended to follow this operational workflow:

First, use sudo apt-get update to update the package list, ensuring local cache information is current. Then use apt-cache policy <package> to query version information for specific packages. If more detailed information is needed, combine apt show <package> and apt-cache show <package>.

For batch queries, consider using the apt-cache madison command, which displays all available versions in tabular format for easy comparison and analysis.

It's worth noting that although apt-get and apt-cache tools are still widely used, the new apt command set is becoming the recommended choice as it integrates functionality from multiple tools, making it more convenient to use.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.