Every package has a version number, in its Version control file field.
dpkg
imposes an ordering on version numbers, so
that it can tell whether packages are being up- or downgraded
and so that dselect
can tell whether a package it
finds available is newer than the one installed on the system.
The version number format has the most significant parts (as
far as comparison is concerned) at the beginning.
The version number format is: [epoch/:]upstream-version[-/debian-revision].
The three components here are:
dpkg
will not usually display the epoch
unless it is essential (non-zero, or if the
upstream-version contains a colon);
dselect
does not display epochs at all in
the main part of the package selection display.
dpkg
's format and comparison scheme.
The comparison behaviour of dpkg
with
respect to the upstream-version is described
below. The upstream-version portion of the
version number is mandatory.
The upstream-version may contain only
alphanumerics and the characters + .
- : (full stop, plus, hyphen, colon)
and should start with a digit. If there is no
debian-revision then hyphens are not allowed;
if there is no epoch then colons are not
allowed.
dpkg
compares it in the same way.
It is optional; if it isn't present then the
upstream-version may not contain a hyphen.
This format represents the case where a piece of
software was written specifically to be turned into a
Debian binary package, and so there is only one
`debianization' of it and therefore no revision
indication is required.
It is conventional to restart the
debian-revision at 1 each time the
upstream-version is increased.
dpkg
will break the
upstream-version and
debian-revision apart at the last hyphen in
the string. The absence of a debian-revision
compares earlier than the presence of one (but note that
the debian-revision is the least significant
part of the version number).
The debian-revision may contain only
alphanumerics and the characters + and
. (plus and full stop).
dpkg
using the same algorithm:
The strings are compared from left to right.
First the initial part of each string consisting entirely of non-digit characters is determined. These two parts (one of which may be empty) are compared lexically. If a difference is found it is returned. The lexical comparison is a comparison of ASCII values modified so that all the letters sort earlier than all the non-letters.
Then the initial part of the remainder of each string which consists entirely of digit characters is determined. The numerical values of these two parts are compared, and any difference found is returned as the result of the comparison. For these purposes an empty string (which can only occur at the end of one or both version strings being compared) counts as zero.
These two steps are repeated (chopping initial non-digit strings and initial digit strings off from the start) until a difference is found or both strings are exhausted.
Note that the purpose of epochs is to allow us to leave behind
mistakes in version numbering, and to cope with situations
where the version numbering changes. It is not there
to cope with version numbers containing strings of letters
which dpkg
cannot interpret (such as
ALPHA or pre-), or with silly orderings (the
author of this manual has heard of a package whose versions
went 1.1, 1.2, 1.3, 1,
2.1, 2.2, 2 and so forth).
If an upstream package has problematic version numbers they should be converted to a sane form for use in the Version field.
If you need to compare version numbers in a script, you may use dpkg --compare-versions .... Type dpkg --help --> --for details on arguments.