Debian Package Management – List Installed Software Robustly

debiandpkgpackage-managementshell-script

So, for now, let's say we only need this to work for debian-based systems (but I will need to be able to do it for yum in the future).

The best I have right now is dpkg-query. So, for example, if I run this:

dpkg-query --show

I'll get a list like this (with a few thousand entries):

...  
sudo    1.8.17p1-2  
...  
vim     2:7.4.1829-1  
...

There is no naming convention though. Some of the packages have the version number in them, some of them have the architecture. ex gcc-4.9-base:amd64, but what I want would only have gcc 4.9. Ideally, I would like to be able to get vendor, product, and version information for all of the software installed. Is there any way to do this natively, or does it have to be some kind of "fuzzy" match?

I'm open to alternative ways of querying the package manager, or some other method that I am not thinking of. I am not able to install additional packages to accomplish this goal (though, I would be interested to see how they work if that exists).

Best Answer

This will list the source packages and versions corresponding to the installed binary packages:

dpkg-query --show -f '${source:Package} ${source:Version}\n' | sort -u

This is the closest match to individual pieces of software you can get automatically: you'll only see gcc-4.9 once, with the associated version, instead of all the corresponding binary packages. You can't easily retrieve "vendor" information, you'd need to look at the package details (apt-cache show ...) or the licensing information (in /usr/share/doc/<package>/copyright — it should point to the "upstream" project, i.e. the "vendor"); this isn't guaranteed to be in machine-readable format so there will be some human parsing involved.

You'll still find some source packages whose name contains the (major) version, e.g. gcc-4.9, gcc-5 etc.; these are unavoidable when packages are designed so that major versions are co-installable, as is the case for GCC.

The equivalent RPM command is

rpm --qf "%{SOURCERPM}\n" -qa | sort -u
Related Question