Methods of payment Abuse

How to get and copy the list of installed packages on Ubuntu/Debian Linux server

  • Main
  • Knowledge base
  • How to get and copy the list of installed packages on Ubuntu/Debian Linux server
01.01.2023, 21:26

A sysadmin needs to get a list of packages for various reasons: reinstalling a system, installing packages on another machine, checking versions and compatibility or other reasons.

How to get a list of Ubuntu / Debian Linux packages?

You can get the packages listed with the command:

dpkg-query -l

A list will appear in the panel with the name, the actual current version and a brief description of the purpose.

For Ubuntu it uses:

sudo apt list --installed

It also outputs a listing of packages with the current version and architecture. There are commands that allow you to output only a list of packages with names, but they are used less frequently).

How to copy and migrate packages on Ubuntu / Debian Linux?

Typically, a system administrator needs to transfer an installed list of packages from one server to another, rather than having to install and/or configure each one individually.

To do this, there are 2 steps to follow:

  1. Save the list of packages from server #1 that were previously output by the command;
  2. Install the dependencies on server #2.

To create a file with a list of installed packages, we use:

dpkg --get-selections | grep -v deinstall > allpackages.txt

The name "allpackages.txt" is for example. You can use any name: "alllists.txt", "lists.txt", "packages.txt" and so on.

The file with the list of packages and versions is copied to server #2 with your address. For example, for 200.200.200.200.200 the command would look like this:

scp allpackages.txt 200.200.200.200:~/

The only thing left to do is to roll the packages from the copied file. To do this, the command is used:

$ sudo apt-get install -y $(< allpackages.txt)

Done! Now you have moved the list of packages from server #1 to server #2.