Sometimes I need to check the installed package version, compare it with the available version, or verify that the correct version is already installed. I will show you how to quickly perform these checks.
Check the version of the installed package
You can quickly check the version of the installed package using dpkg
command.
$ dpkg -s cpp Package: cpp Status: install ok installed Priority: optional Section: interpreters Installed-Size: 63 Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org> Architecture: amd64 Multi-Arch: allowed Source: gcc-defaults (1.120) Version: 4:4.7.2-1 Depends: cpp-4.7 (>= 4.7.2-1~) Suggests: cpp-doc Conflicts: cpp-doc (<< 1:2.95.3) Description: GNU C preprocessor (cpp) The GNU C preprocessor is a macro processor that is used automatically by the GNU C compiler to transform programs before actual compilation. . This package has been separated from gcc for the benefit of those who require the preprocessor but not the compiler. . This is a dependency package providing the default GNU C preprocessor.
Print the most important information in the table.
$ dpkg -l cpp Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==================-============-================-=========================== ii cpp 4:4.7.2-1 amd64 GNU C preprocessor (cpp)
A more efficient solution would be to filter package version using grep
command.
$ dpkg -s cpp | grep Version Version: 4:4.7.2-1
Use dpkg-query
utility to output data using a custom format.
$ dpkg-query -W --showformat='${Package} version ${Version} for architecture ${Architecture}\n' cpp cpp version 4:4.7.2-1 for architecture amd64
You will receive an error if the given package is not installed.
$ dpkg -s mc dpkg-query: package 'mc' is not installed and no information is available Use dpkg --info (= dpkg-deb --info) to examine archive files, and dpkg --contents (= dpkg-deb --contents) to list their contents.
Check the version of the installed or available package
apt-cache
Use this command to query APT cache and list current and available package versions.
$ apt-cache policy iceweasel iceweasel: Installed: 31.2.0esr-2~deb7u1 Candidate: 31.2.0esr-2~deb7u1 Version table: *** 31.2.0esr-2~deb7u1 0 500 http://security.debian.org/ wheezy/updates/main amd64 Packages 100 /var/lib/dpkg/status 24.4.0esr-1~deb7u2 0 500 http://ftp.task.gda.pl/debian/ wheezy/main amd64 Packages
aptitude
Current and available package versions can also be displayed using aptitude
utility.
$ aptitude versions ^iceweasel$ Package iceweasel: p A 24.4.0esr-1~deb7u2 stable 500 i A 31.2.0esr-2~deb7u1 stable 500
Of course, you can print data using the custom format in columns or without them.
$ aptitude search snort -F "%c %M %p %V %v" p fwsnort 1.6.2-1 <none> i snort 2.9.2.2-3 2.9.2.2-3 i A snort-common 2.9.2.2-3 2.9.2.2-3 i A snort-common-libraries 2.9.2.2-3 2.9.2.2-3 p snort-doc 2.9.2.2-3 <none> p snort-mysql 2.9.2.2-3 <none> p snort-pgsql 2.9.2.2-3 <none> v snort-rules <none> <none> i A snort-rules-default 2.9.2.2-3 2.9.2.2-3
Use an additional --disable-columns
parameter if you want to disable columns.
Ending notes
Please read dpkg
, dpkg-query
, aptitude
manual pages and install aptitude-doc-en
package for additional information.