Create a list of all installed packages & install the same packages on your new server.

This tutorial will show you how to list and filter installed packages on Ubuntu. Knowing how to list installed packages on your Ubuntu system can be helpful in situations where you need to install the same packages on another machine or if you want to reinstall your system.

We will also show you how to check whether a specific package is installed, count installed packages, and find out the version of an installed package.

Although this tutorial is written for Ubuntu, the instructions apply to any Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.

List Installed Packages with Apt #

apt is a command-line interface for the package management system. It was introduced in Ubuntu 14.04 and combines the most commonly used commands from apt-get and apt-cache including an option to list installed packages.

To list the installed packages on your Ubuntu system, use the following command:

sudo apt list --installed

As you can see from the output above, the command prints a list of all installed packages, including information about the versions and architecture of the packages.

The packages list is long, and it is a good idea to pipe the output to less to make it easier to read:

sudo apt list --installed | less

If, you want to find whether a specific package is installed, you can filter the output with the grep command. For example, to find out if the screen package is installed on our system, we will run:

sudo apt list --installed | grep screen

Output:

screen/bionic,now 4.6.2-1 amd64 [installed]

The output above shows that we have screen version 4.6.2-1 installed on our system.

List Installed Packages with dpkg-query

If you are running an older Ubuntu version , then you can use the dpkg-query command to list the packages:

sudo dpkg-query -l | less

The command will show you a list of all installed packages, including the package’s versions, architecture, and a short description.

You can filter the dpkg-query -l output with grep, same as the apt output:

sudo dpkg-query -l | grep package_name
Create a list of all installed packages #

To create a list of the names of all installed packages on your Ubuntu or Debian system and save it in a file named packages_list.txt, run the following command:

sudo dpkg-query -f '${binary:Package}\n' -W > packages_list.txt

Now that you have the list, if you want to install the same packages on your new server, you can do that with the following:

sudo xargs -a packages_list.txt apt install
Count the number of packages installed on your Ubuntu machine #

To find out how many packages are installed on your system, you can use the same command as before, but instead of redirecting the output to a file, you can pipe it to the wc utility and count the lines:

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

Output:

544

As you can see, I have 544 packages installed on my Ubuntu server.

Conclusion #

By now, you should know how to list and filter installed packages on your Ubuntu system. If you want to learn more about the apt command open your terminal and type man apt.

Feel free to leave a comment if you have any questions.

Similar Posts