In some situations we need to know which packages we have installed in a Debian or Ubuntu system. In that case, we can use the tool dpkg, which will give us the information we need.
dpkg
Next command will give us the current packages installed with different states:
dpkg --get-selections
The states we can have are:
- install: The package is selected for installation.
- hold: A package marked to be on hold is not handled by dpkg, unless forced to do that with option –force-hold.
- deinstall: The package is selected for deinstallation (i.e. we want to remove all files, except configuration files).
- purge: The package is selected to be purged (i.e. we want to remove everything from system directories, even configuration files).
If we want to filter packages, we can combine dpkg tool with grep tool. Here an example to filter the packages related with nginx:
$ dpkg --get-selections | grep nginx
libnginx-mod-http-geoip install
libnginx-mod-http-image-filter install
libnginx-mod-http-lua install
libnginx-mod-http-ndk install
libnginx-mod-http-xslt-filter install
libnginx-mod-mail install
libnginx-mod-stream install
nginx install
nginx-common install
nginx-core install
python3-certbot-nginx install
Also, you could export the result of the command to a file:
$ dpkg --get-selections > ~/packages.txt
dpkg -l
An alternative to the previous option is to use dpkg -l
which will also list the installed packages with the version, the architecture and a description. The difference with the previous command is that in this case we don’t have the state of the package.
The example would be:
$ dpkg -l | grep nginx
ii libnginx-mod-http-geoip2 1.18.0-6ubuntu14.1 arm64 GeoIP2 HTTP module for Nginx
ii libnginx-mod-http-image-filter 1.18.0-6ubuntu14.1 arm64 HTTP image filter module for Nginx
ii libnginx-mod-http-xslt-filter 1.18.0-6ubuntu14.1 arm64 XSLT Transformation module for Nginx
ii libnginx-mod-mail 1.18.0-6ubuntu14.1 arm64 Mail module for Nginx
ii libnginx-mod-stream 1.18.0-6ubuntu14.1 arm64 Stream module for Nginx
ii libnginx-mod-stream-geoip2 1.18.0-6ubuntu14.1 arm64 GeoIP2 Stream module for Nginx
ii nginx 1.18.0-6ubuntu14.1 arm64 small, powerful, scalable web/proxy server
ii nginx-common 1.18.0-6ubuntu14.1 all small, powerful, scalable web/proxy server - common files
ii nginx-core 1.18.0-6ubuntu14.1 arm64 nginx web/proxy server (standard version)
ii python3-certbot-nginx 1.21.0-1 all Nginx plugin for Certbot
apt list
And finally we have an alternative with apt to see installed packages.
This is the example with nginx.
$ apt list --installed | grep -i nginx
libnginx-mod-http-geoip2/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
libnginx-mod-http-image-filter/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
libnginx-mod-http-xslt-filter/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
libnginx-mod-mail/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
libnginx-mod-stream-geoip2/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
libnginx-mod-stream/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
nginx-common/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 all [installed, automatic]
nginx-core/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed, automatic]
nginx/jammy-updates,jammy-security,now 1.18.0-6ubuntu14.1 amd64 [installed]
python3-certbot-nginx/jammy,now 1.21.0-1 all [installed]