Guidelines

This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes
116 views
116 views

We're in the process of migrating customer systems to a new platform. On the new platform the servers should be installed with a more recent Ubuntu version, but the packages should remain the same (as far as is applicable).

I suppose I could do something like

dpkg -l | awk '/^ii/ {print $2}'

and then feed the resulting list to apt-get install, but isn't there a more elegant approach?

in Sysadmin
by (100)
1 7 21
edit history

Please log in or register to answer this question.

1 Answer

0 votes
 

dpkg has a parameter --get-selections that allow you to export a list of the installed packages. On the old system run

dpkg --get-selections > packages.lst

and transfer the resulting file (packages.lst) to the new system where you import it using the complementary parameter --set-selections:

dpkg --set-selections < packages.lst

This may produce the below warning:

dpkg: warning: found unknown packages; this might mean the available database
is outdated, and needs to be updated through a frontend method;
please see the FAQ https://wiki.debian.org/Teams/Dpkg/FAQ

which can mean any of the following two things:

  • the package database needs to be updated (as the message claims), or
  • some packages are not available for this OS release.

The former is easily addressed by one of the commands listed in the FAQ, e.g.

apt-cache dumpavail | dpkg --merge-avail

The latter can be ignored if the packages in question aren't relevant anymore (like the packages upstart and upstart-sysv when going from Ubuntu Xenial to a more recent version). If there are packages you still need, even though they're not provided by the distro anymore, you need to find a different source for them. I do not recommend copying packages over from an older distro version, as that tends to lead to dependency conflicts.

Import the package list again if you had to update the database, then apply the selections by running the following command:

apt-get dselect-upgrade
by (100)
1 7 21
edit history
...