Listing Installed Packages on Ubuntu

Overview

There are a variety of reasons why someone would want to list all installed packages on an Ubuntu Server install. One reason may be for audit and compliance reasons, perhaps you are about to venture into infrastructure as code.

When writing Ansible playbooks or Puppet modules, for example, of an existing server, it is important to have detailed documentation of the server’s configuration.

There are two methods of listing installed packages on Ubuntu servers. The one you choose will depend on the version of Ubuntu and installed and how much information you need to document.

List Installed Packges with Apt

To list all installed packages with the apt command we use the list command with the–installed flag. The flag instructs apt to only return installed packages. Without the flag, apt will generate a list of packages available from all configured repositories.

sudo apt list --installed

You should see output similar to the following. Of course, the contents will depend on what is installed on your system. Each line will display the package name, version, and architecture.

Listing... Done
 accountsservice/bionic,now 0.6.45-1ubuntu1 amd64 [installed]
 acl/bionic,now 2.2.52-3build1 amd64 [installed]
 acpid/bionic,now 1:2.0.28-1ubuntu1 amd64 [installed]
 adduser/bionic,now 3.116ubuntu1 all [installed]
 apparmor/bionic-updates,bionic-security,now 2.12-4ubuntu5.1 amd64 [installed]
 apport/bionic,now 2.20.9-0ubuntu7 all [installed,upgradable to: 2.20.9-0ubuntu7.6]
 apport-symptoms/bionic,now 0.20 all [installed]
 apt/bionic,now 1.6.1 amd64 [installed,upgradable to: 1.6.10]
 apt-transport-https/bionic-updates,now 1.6.10 all [installed]
 apt-utils/bionic,now 1.6.1 amd64 [installed,upgradable to: 1.6.10]
 at/bionic,now 3.1.20-3.1ubuntu2 amd64 [installed]
 aufs-tools/bionic,now 1:4.9+20170918-1ubuntu1 amd64 [installed,automatic]
 base-files/bionic,now 10.1ubuntu2 amd64 [installed,upgradable to: 10.1ubuntu2.4]
 base-passwd/bionic,now 3.5.44 amd64 [installed]
 bash/bionic,now 4.4.18-2ubuntu1 amd64 [installed]
 bash-completion/bionic,now 1:2.8-1ubuntu1 all [installed]
 bc/bionic,now 1.07.1-2 amd64 [installed]
 bcache-tools/bionic,now 1.0.8-2build1 amd64 [installed]
 bind9-host/bionic-updates,bionic-security,now 1:9.11.3+dfsg-1ubuntu1.7 amd64 [installed]
 bsdmainutils/bionic,now 11.1.2ubuntu1 amd64 [installed]
 bsdutils/bionic,now 1:2.31.1-0.4ubuntu3 amd64 [installed,upgradable to: 1:2.31.1-0.4ubuntu3.3]
 btrfs-progs/bionic,now 4.15.1-1build1 amd64 [installed]
 

List Installed Packages with Dpkg

An alternative to apt is to use the dpkg. This solution is not as intuitive as the former, however, it is the only viable one when running Ubuntu 13.04 or lower.

The –get-selections flag is used with dpkg manager to list packages. Unfortunately, this flag alone will not display a resulting list of installed packages. In order to generate a list of only installed packages, we must pipe the results into grep, and then invert the results to include only items that do not include the keyword deinstall.

dpkg --get-selections | grep -v deinstall

The output of the command will look similar to the following example. Notice that it doesn’t provide the same amount of informations as the apt list command used earler.

accountsservice install
 acl install
 acpid install
 adduser install
 apparmor install
 apport install
 apport-symptoms install
 apt install
 apt-transport-https install
 apt-utils install
 at install
 aufs-tools install
 base-files install
 base-passwd install
 bash install
 bash-completion install
 bc install
 bcache-tools install
 bind9-host install
 bsdmainutils install
 bsdutils install
 btrfs-progs install
 btrfs-tools install
 busybox-initramfs install
 busybox-static install
 byobu install
 bzip2 install
 ca-certificates install
 cgroupfs-mount install
 

For more information about the packages installed on your server, you can use the -l or –list flags.

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  accountsservice                                0.6.45-1ubuntu1              amd64                        query and manipulate user account information
 ii  acl                                            2.2.52-3build1               amd64                        Access control list utilities
 ii  acpid                                          1:2.0.28-1ubuntu1            amd64                        Advanced Configuration and Power Interface event daemon
 ii  adduser                                        3.116ubuntu1                 all                          add and remove users and groups
 ii  apparmor                                       2.12-4ubuntu5.1              amd64                        user-space parser utility for AppArmor
 ii  apport                                         2.20.9-0ubuntu7              all                          automatically generate crash reports for debugging
 ii  apport-symptoms                                0.20                         all                          symptom scripts for apport
 ii  apt                                            1.6.1                        amd64                        commandline package manager
 ii  apt-transport-https                            1.6.10                       all                          transitional package for https support
 ii  apt-utils                                      1.6.1                        amd64                        package management related utility programs
 ii  at                                             3.1.20-3.1ubuntu2            amd64                        Delayed job execution and batch processing
 ii  aufs-tools                                     1:4.9+20170918-1ubuntu1      amd64                        Tools to manage aufs filesystems
 ii  base-files                                     10.1ubuntu2                  amd64                        Debian base system miscellaneous files
 ii  base-passwd                                    3.5.44                       amd64                        Debian base system master password and group files
 ii  bash                                           4.4.18-2ubuntu1              amd64                        GNU Bourne Again SHell
 ii  bash-completion                                1:2.8-1ubuntu1               all                          programmable completion for the bash shell
 ii  bc                                             1.07.1-2                     amd64                        GNU bc arbitrary precision calculator language
 ii  bcache-tools                                   1.0.8-2build1                amd64                        bcache userspace tools
 ii  bind9-host                                     1:9.11.3+dfsg-1ubuntu1.7     amd64                        DNS lookup utility (deprecated)
 ii  bsdmainutils                                   11.1.2ubuntu1                amd64                        collection of more utilities from FreeBSD
 ii  bsdutils                                       1:2.31.1-0.4ubuntu3          amd64                        basic utilities from 4.4BSD-Lite
 ii  btrfs-progs                                    4.15.1-1build1               amd64                        Checksumming Copy on Write Filesystem utilities
 ii  btrfs-tools                                    4.15.1-1build1               amd64                        transitional dummy package
 ii  busybox-initramfs                              1:1.27.2-2ubuntu3.2          amd64                        Standalone shell setup for initramfs
 ii  busybox-static                                 1:1.27.2-2ubuntu3.2          amd64                        Standalone rescue shell with tons of builtin utilities
 ii  byobu                                          5.125-0ubuntu1               all                          text window manager, shell multiplexer, integrated DevOps environment
 ii  bzip2                                          1.0.6-8.1                    amd64                        high-quality block-sorting file compressor - utilities
 

The list above provides for more valuable information of a package’s version, targeted architecture, and includes a brief description.

Summary

Listing installed packages is an important step when you move into infrastructure as code. The information provided can then be used to generate configuration management scripts, from Puppet, Chef, and Ansible, for example.

The information may also be helpful during system audits. You may need to document your servers to satisfy compliance requirements.