wiki:WhenToUseTheStupidTildeInVersionNumbers

Version 1 (modified by jdreed, 11 years ago) (diff)

--

When specifying version numbers, such as in dpkg --compare-versions or the various control fields (e.g. Depends:, Conflicts:, etc), you may notice that in some cases there is a tilde after the version number (e.g. 1.4~) and in some cases there isn't.

According to  Debian Policy:

The lexical comparison is a comparison of ASCII values modified so that all the letters sort earlier than all the non-letters and so that a tilde sorts before anything, even the end of a part. For example, the following parts are in sorted order from earliest to latest: , a, ~, the empty part, a.
...
One common use of ~ is for upstream pre-releases. For example, 1.0~beta1~svn1245 sorts earlier than 1.0~beta1, which sorts earlier than 1.0.

A good rule of thumb is that the tilde is generally needed for earlier (<<, lt) and later-or-equal (>=, ge) comparisons, and not needed for later (>>, gt) or earlier-or-equal (<=, le).

When using dpkg --compare-versions, not that by default an empty version (i.e. the package is not installed or the package is being installed for the first time, depending on context) is treated as the earliest possible version. The lt, le, gt, and ge comparison operators have alternative versions with a trailing -nl (e.g. gt-nl) which treat an empty version as the latest possible version. When constructing dpkg --compare-versions conditionals, remember to verify that the flow control is correct for both upgrade and fresh installs.