== Comparing RPM versions in the shell Via [[Planet Debian http://planet.debian.org/]] I recently read [[Comparing version numbers in the shell http://www.df7cb.de/blog/2014/Comparing_Version_Numbers_in_Shell.html]], which sort of suggests using _sort -V_ to compare package version numbers on RPM-derived systems. My reaction to this is kind of mixed, because how good an idea this is depends on what you're trying to do with this comparison. If you just want to compare generic version numbers, '_sort -V_' may do what you want. You should read the coreutils documentation for _sort_ very carefully, especially [[Details about version sort https://www.gnu.org/software/coreutils/manual/html_node/Details-about-version-sort.html]], because how it works may not be quite what you expect or what you want. You probably want to test it. If you want to compare version numbers in the same way that RPM does it, so that your idea of a 'newer version' specifically matches what eg '_rpm -U_' or '_yum localupdate_' would conclude, you should use the _rpmdev-vercmp_ command (it's part of the _rpmdevtools_ package). This uses RPM's actual version comparison code (as exposed through the RPM Python bindings). See '_rpmdev-vercmp -h_' for basic usage and then experiment with it; note that it prints output and has somewhat odd status returns. You may also want to see '_rpmdev-sort_'. (If you just care about version numbers, you can ignore the epoch and the release parts of ordinary RPM version numbering; _rpmdev-vercmp_ doesn't require you to supply them.) If you want to compare the versions of actual RPM packages as _rpm_ and _yum_ do it, you really have to use _rpmdev-vercmp_ and you need to extract full RPM version information about both packages, including their RPM epochs if any. It's a pity that there is no easy command to print out the full version information that _rpmdev-vercmp_ requires (it's a bit complex and annoying for reasons covered [[here RPMEpochNumbers]], although for most purposes you can apparently consider a missing epoch number to be equal to an epoch number of '0'). As it turns out, the best approximation of quickly printing out full RPM version information for _rpmdev-vercmp_ purposes is something like: > rpm -q --qf '%{N} %{epochnum}:%{V}-%{R}\n' ... Note that you should not accidentally give _rpmdev-vercmp_ strings that have the package name in them; it will consider them to be the version and then interpret the version number as the first part of the release numbering (I think). (I discovered _rpmdev-vercmp_ via [[this stackoverflow question and its answer http://stackoverflow.com/questions/2996279/how-does-yum-compare-versions]] when I was researching this entry. Once again writing blog entries has proven usefully educational.)