In this tutorial, we will explain how to list and filter installed packages on Debian . We will also show you how to check if a particular package is installed, count installed packages and find out the version of the installed package.
Knowing how to list installed packages on a Debian-based system can be useful in case you need to install the same packages on another machine or if you want to reinstall your system.
How to list installed packages on Debian
List installed packages with Apt
Apt is a command line interface to the package management system and combines the most commonly used functions apt-get and apt-cache including an option to list installed packages.
To list all the packages installed on your system, run the following command:
sudo apt list --installed
Output:
adduser/stable,now 3.115 all [installed] apt/stable,now 1.4.8 amd64 [installed] apt-listchanges/stable,now 3.10 all [installed] apt-utils/stable,now 1.4.8 amd64 [installed] autoconf/stable,now 2.69-10 all [installed] automake/stable,now 1:1.15-6 all [installed] autotools-dev/stable,now 20161112.1 all [installed,automatic] base-files/stable,now 9.9+deb9u5 amd64 [installed] base-passwd/stable,now 3.5.43 amd64 [installed] bash/stable,now 4.4-5 amd64 [installed]
The command will display a list of all installed packages including information about package versions and architectures. The rightmost column in the output indicates whether the package was automatically installed as a dependency of another package.
Since the list of packages is long, you should pipe the output to the less command for better readability:
sudo apt list --installed | less
To find out if a particular package is installed, use the grep command to filter the output. For example, to find if the tmux package is installed on the system you will enter:
sudo apt list --installed | grep tmux
Output:
tmux/stable,now 2.3-4 amd64 [installed]
The above output shows that you have tmux 2.3-4 installed on your system.
List installed packages with dpkg-query
dpkg-query is a command line that can be used to display information about packages listed in the dpkg database.
To get a list of all installed package types:
sudo dpkg-query -l | less
The command will display a list of all installed packages including package versions, architectures and a short description.
You can filter dpkg-query -l output with the grep command :
sudo dpkg-query -l | grep package_name_to_search
Generate a list of all installed packages
The following command will save the list of all installed packages on your Debian system to a file named packages_list.txt :
sudo dpkg-query -f '${binary:Package}\n' -W > packages_list.txt
Now that you have the list, you can install the same packages on your new server with:
sudo xargs -a packages_list.txt apt install
Count the number of installed packages
To know how many packages are installed on your system you can use the same command as when generating the package list but instead of redirecting the output to a file you can redirect it to the wc count command current:
sudo dpkg-query -f '${binary:Package}\n' -W | wc -l
The output will show the number of installed packages:
466
Conclude installed packages on Debian
In this tutorial, you learned how to list and filter installed packages on your Debian system.