Applies to: apt and dpkg on Ubuntu 24.04 and 26.04, Debian 12 and 13

Ubuntu and Debian keep a database of every installed package. You can read it with apt (easy to read) or dpkg (better for scripts). We tested every command on Ubuntu 24.04 and Debian 13. For AlmaLinux, Rocky Linux and RHEL, see how to list installed packages on RHEL-based systems.

List all installed packages

apt list --installed

Each line shows the package, its repository, the version and the architecture, for example openssl/noble-updates,now 3.0.13-0ubuntu3.15 amd64 [installed,automatic]. automatic means it was installed as a dependency. The first line is just Listing.... When you pipe the output into another command, apt also prints a warning that its command-line interface is not stable; it is harmless.

Search for one package

apt list --installed | grep nginx
dpkg -l | grep nginx          # "ii" in the first column means installed
dpkg -s nginx                 # full details: status, version, dependencies

Count installed packages

dpkg-query -f '${binary:Package}\n' -W | wc -l

Only the packages you installed yourself

apt-mark showmanual

This leaves out packages that came in as dependencies, which makes it a good list to rebuild a server from.

Save the list and reinstall it on another server

apt-mark showmanual > packages.txt                   # on the old server
sudo apt update                                      # on the new server
sudo xargs -a packages.txt apt-get install -y

Both servers should run the same Ubuntu or Debian release. If you use dpkg --get-selections and dpkg --set-selections instead, run sudo apt-cache dumpavail | sudo dpkg --merge-avail on the new server first. Without it, dpkg ignores packages it doesn’t know yet, and apt-get dselect-upgrade installs nothing new; we saw exactly that in our test.

When was a package installed?

grep -E "^(Start-Date|Commandline)" /var/log/apt/history.log | tail -20

Older entries are in the compressed history.log.*.gz files (read them with zcat).

Snap packages

Ubuntu can also have snap packages, which apt does not list. Show them with snap list.

To see which files a package installed, see how to find where a package installed its files.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)