Spiffy Way To Migrate All Installed Packages Between Linux Ubuntu Servers (Upgrades Too!)

Migrate Linux Servers

Are you looking for ways to Migrate Linux Servers between multiple installations? I’ve experimented with various Linux tools & configurations over the years & sometimes there is a need to migrate between Virtual Machines or hardware. It takes a considerable amount of time to have to reconfigure a Linux Ubuntu server from scratch & fine tune everything, over & over again.

One of the better guides that I’ve seen to help get started out with the process of getting all the installed packages from the old Linux Ubuntu Server to the new one can be found at: https://www.cyberciti.biz/faq/how-to-list-all-installed-packages-debian-ubuntu

What I like the most about this guide is the variety of options & possibilities it provides to accomplish installing (or perhaps re-installing, in some cases) the packages from the original Linux Ubuntu Server setup.

The Missing Steps to Migrate Linux Servers

Over the years, I’ve come across a TON of tutorials on this subject that seem to leave out the method for cleaning up the output file for parsing. Unfortunately, the Cyberciti.biz guide I shared is no exception.

For the section:

How to save a list to a text file

The syntax is as follows on server1:

$ dpkg --get-selections | grep -v deinstall > installed_packages_list.txt

This ends up giving you a text file formatted like this:


You will get gripes about “install” not being a package in APT (or YUM for CentOS & Red Hat) if you skip straight to using:


How Fix Exported Installed Packages List File For Use With ‘apt-get install’

You need to get rid of all the “orphaned” ‘install’ strings between the tabs & newline chars, & then properly space the text of the installed package list first. There may also be a difference in platform such as amd64 vs i386 that you need to account for. If your platform requires a specific platform version of a package, you don’t (typically?) need to include the xxxxx:amd64 or xxxxx:i386 in the package name when installing, the system will (or should!) determine that for you “automagically”. You WILL need to pick out the packages that you DO NOT want to install all in one shot, still. You will likely get some “nags” about specific packages when there is a problem.

To do that, I’m a fan of this Perl5 one-liner:

This tweaks the file to look like this instead, which will actually work with that final step using “apt-get install -y” :

... dpkg e2fslibs e2fsprogs ed eject emacsen-common fail2ban ...


IMPORTANT NOTE: There has yet to be a guide or even a “migration script” that can account for every single nuance involved in migrating between Linux Ubuntu Server installations. Guides like these are just that: Guides. I have tried to create posts that fulfill the glaring holes in available information on the web. With as many websites & forum pages as there are on the internet today, it’s still kind of incredible to stumble upon issues & questions that have either non-existent information for them, or its splintered & scattered around in multiple locations & needs congealed into an organized resource.

The Manual Intervention Required for Your Unique Linux Server Migration Requirements

You will STILL NEED TO “cherry pick” the installed packages list from the properly formatted version the above Linux command-line commands will result in! For example, if you use both Apache & Nginx together in a local reverse proxy configuration, you won’t be able to install both Apache (package name: ‘apache2’ in Linux Ubuntu Server 16.04.3 LTS & 17.04+) & Nginx (package name: ‘nginx’, respectively) at the same time because upon initial installation, they both require port 80 to be open. The quickest fix for getting them both installed is to install one of them first, ‘stop’ the service running, then run the apt-get install -y ‘package-name’ after. For example, if we have installed ‘apache2’ first (which seems to be the case, most of the time) then we would need to do the following to get ‘nginx’ installed:

In the above command line examples, you may swap ‘apache2’ with ‘nginx’ for your needs. Before you will be able to run them both together on the same server, you will need to change at least one of them to not use port 80 first. It gets even more tricky when you are running SSL connections on port 443, etc, but since this is a guide to help migrate between servers, there is a good chance that you will simply be able to move your OLD configuration files onto the new server (eg: SCP/SFTP/FTP the old /etc/apache2/ & /etc/nginx/ directories over to the new server in the identical directory paths) & simply reboot afterwards.

Final Thoughts About (Debian) Linux Ubuntu Server Migrations

I also ran into issues with applications like EHCP (Easy Hosting Control Panel), EHCP (Force Edition) or Webmin where the installation packages need to be manually downloaded from outside the APT repositories. You will likely need to manually download those packages again & then you might be able to import the configuration to the new server that matches the old one. There is a chance you will have to manually reconfigure a few things yourself again though. Such as the /etc/network/interfaces file to configure a static IP address for the new server that may be on a different network from the old server.

If anyone reading this comes across an issue that they would like some help with regarding Linux Ubuntu Server migration (or any Debian-based Linux Server distro, really) post your questions in the comments section & I will try to help you out.

UPDATE: The well respected (and frankly brilliant) Vivek Gite accepted my comment into the very popular blog page that I linked to above (along with a kind note of gratitude): https://www.cyberciti.biz/faq/how-to-list-all-installed-packages-debian-ubuntu/#comment-920788



Leave a Reply