Every package has a version number recorded in its Version control file field.
The package management system imposes an ordering on version numbers, so that it can tell whether packages are being up- or downgraded and so that package system front end applications 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:
It is provided to allow mistakes in the version numbers of older versions of a package, and also a package's previous version numbering schemes, to be left behind.
The comparison behavior of the package management system 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.
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 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.
The package management system will break the version number apart at the last hyphen in the string (if there is one) to determine the upstream_version and debian_revision. 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 upstream_version and debian_revision parts are compared by the package management system 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 (comparing and removing initial non-digit strings and initial digit strings) are repeated 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 scheme changes. It is not intended to cope with version numbers containing strings of letters which the package management system 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.
In general, Debian packages should use the same version numbers as the upstream sources.
However, in some cases where the upstream version number is based on a date (e.g., a development `snapshot' release) the package management system cannot handle these version numbers without epochs. For example, dpkg will consider `96May01' to be greater than `96Dec24'.
To prevent having to use epochs for every new upstream version, the version number should be changed to the following format in such cases: `19960501', `19961224'. It is up to the maintainer whether he/she wants to bother the upstream maintainer to change the version numbers upstream, too.
Note that other version formats based on dates which are parsed correctly by the package management system should not be changed.
Native Debian packages (i.e., packages which have been written especially for Debian) whose version numbers include dates should always use the `YYYYMMDD' format.
Debian Policy Manualversion 18.104.22.168, 2002-03-14