vercmp
Compare two version strings lexicographically
SYNOPSIS
vercmp version1 version2
PARAMETERS
version1
The first version string to compare. This should adhere to RPM's versioning format (e.g., 1.0, 1.2.3-1.fc34, 1:2.0).
version2
The second version string to compare against. This also should follow RPM's versioning conventions.
DESCRIPTION
vercmp is a utility typically found on RPM-based Linux distributions, used to compare two version strings according to the RPM Package Manager's versioning rules. This comparison logic is crucial for package management, determining which package version is "newer" for upgrades or dependency resolution. It returns an exit code indicating whether the first version is less than, equal to, or greater than the second. The comparison algorithm handles various versioning complexities including epochs, releases, pre-releases, and differing alphanumeric components, ensuring consistency with RPM's internal logic.
CAVEATS
The comparison logic used by vercmp is specific to RPM's rules, which may differ significantly from other package managers (like dpkg on Debian/Ubuntu systems) or generic lexicographical or numeric sorting algorithms. It specifically handles:
- Epochs: A numeric prefix followed by a colon (e.g., 1:2.0). Epochs are compared numerically first.
- Numerics: Segments of digits are compared numerically. Trailing zeros within numeric segments are ignored (e.g., 1.0 is equal to 1).
- Alphabetics: Segments of letters are compared lexicographically.
- Tilde (~): The tilde character often denotes a pre-release version, making it sort before a version without a tilde (e.g., 1.0~beta < 1.0).
- Other Characters: Other non-alphanumeric characters usually act as delimiters.
EXIT CODES
The vercmp command communicates the comparison result through its exit code:
- 0: version1 is equal to version2.
- 1: version1 is greater than version2.
- 2: version1 is less than version2.
- 3: An error occurred (e.g., invalid arguments).
HISTORY
vercmp emerged from the necessity of the RPM Package Manager to reliably determine version precedence for package upgrades and dependency resolution. It provides a standalone utility to externalize the same robust version comparison algorithm used internally by rpm, allowing developers and scripts to perform consistent version checks.