Debian-based operating systems use APT (short for Advanced Package Tool), a package manager designed with ease-of-use and automation in mind. It is pre-Installed on most Debian-based operating systems, making software installation and management as simple as possible.
However, a lot of functionality is hidden away behind commands and options, making it difficult for newer users to find these features. In this tutorial, we will show you how to list all installed packages with APT on your Debian based virtual server.List All Installed Packages With APT on Debian
Open a Terminal/Connect to your server using SSH.
APT as a program is only available through a terminal. To access APT, open up a Terminal on your Debian machine, or if you are using a Debian VPS, connect to your VPS using SSH.
Use APT to list all installed packages on the system.
Entering the following command will cause APT to print all installed packages on your system.
sudo apt list --installed
The Output will be similar to this:
Listing... Done adduser/stable,now 3.115 all [installed] anacron/stable,now 2.3-24 amd64 [installed,automatic] 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] avahi-autoipd/stable,now 0.6.32-2 amd64 [installed,automatic] base-files/stable,now 9.9+deb9u4 amd64 [installed] base-passwd/stable,now 3.5.43 amd64 [installed] bash/stable,now 4.4-5 amd64 [installed] (continued)
Using the “less” command
Now, you can go through your listings by using the “less” command – this makes the list scrollable, and the output will wait for you to scroll down with your arrow keys. Simply pipe the command into less to make your output more controllable. Less also has many other output commands, so look them up on the man page to unlock the full potential of less.
sudo apt list --installed | less
This should give you a single-page output:
Listing... adduser/stable,now 3.115 all [installed] anacron/stable,now 2.3-24 amd64 [installed,automatic] 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] avahi-autoipd/stable,now 0.6.32-2 amd64 [installed,automatic] base-files/stable,now 9.9+deb9u4 amd64 [installed] base-passwd/stable,now 3.5.43 amd64 [installed] bash/stable,now 4.4-5 amd64 [installed] (continued)
Filtered Searches Using grep
Searching for specific packages can be done by using the “grep” command, a widely used and very powerful search tool included on most Linux distributions. Use a pipe to have grep output its search results.
sudo apt list --installed | grep bash
And here’s the output (results may vary)
bash/stable,now 4.4-5 amd64 [installed] bash-completion/stable,now 1:2.1-4.3 all [installed]
With grep, you can stack many options to only output certain results, not output the entire line, remove case sensitivity, and so on. You can also pipe these results into less to get a scrolling output if you have many search results.
Outputting To a File
All of these combined can then be outputted to a file by using the ‘>’ and ‘>>’ operators. ‘>’ overwrites any file with the output of any command, while ‘>>’ only adds to the end of the file (appending). So, if you wanted to output the results of the list to a file called ‘testfile.txt’, you would execute the following command:
sudo apt list --installed > testfile.txt
You can then keep this file to keep a record of what packages were installed on your system at a specific time, or you can use this file to install packages on a new system.
Alternative Method: Checking Through dpkg
While APT might not come pre-installed on every Debian-based system, ‘dpkg’ is included on every system. dpkg is the underlying software that allows APT to function correctly. It only has core functionality for installing and removing packages – but, it can do understand more advanced commands as well, such as listing info on packages.
You can even list all installed packages using dpkg as follows:
sudo dpkg -l
The output will look similar to this:
Name Version Architecture Description +++-============-===========-=================-====================================== ii adduser 3.115 all add and remove users and groups ii anacron 2.3-24 amd64 cron-like program that doesn't go by time ii apt 1.4.8 amd64 commandline package manager
And like before, you can also use grep and less to make the searching process that much easier. Dpkg can sometimes be preferable over APT – the format of output is cleaner, and it offers more information about each package, such as a description of what the package is, as well as what processor architecture the package supports. However, APT’s output is more friendly to use for scripting and automation purposes, such as batch installing a lot of packages on a system. Both APT and dpkg support looking up the information of a specific package, meaning that no matter which you choose, you can be sure you will be getting the information that you need.
PS. If you liked this post, on how to list all installed packages using APT on your virtual server with Debian OS, please share it with your friends through social networks by using the buttons below, or simply leave a reply. Thanks.