Replicate Installed Package Selections From One Ubuntu System To Another
Overview
This guide shows how to restore all packages used in an Ubuntu instance into another one, to have the same programs available.
Having a backup of the software used is a good practice to easily replicate your environments accross multiple machines.
Here I will show you a method using apt-mark.
apt-mark can be used as a unified front-end to set various settings for a package, such as marking a package as being automatically/manually installed or changing dpkg selections such as hold, install, deinstall and purge which are respected e.g. by apt-get dselect-upgrade or aptitude.
There are two kinds of packages that are of interest for this purpose:
- automatically installed packages: packages will be removed when no more manually installed packages depend on these packages
- manually installed packages: prevents packages from being automatically removed if no other packages depend on them.
In other terms: manual packages are those installed by us, auto packages are those which came already installed or are dependencies of other packages.
1. List packages using apt-mark
apt-mark handles various settings for packages. We can separate our backup files in two files:
- One will hold the packages installed automatically
- Other file will hold the packages we installed manually
- apt-mark showauto
showauto is used to print a list of automatically installed packages with each package on a new line. All automatically installed packages will be listed if no package is given. If packages are given only those which are automatically installed will be shown.
- apt-mark showmanual
showmanual can be used in the same way as showauto except that it will print a list of manually installed packages instead.
So we create these two files:
$ apt-mark showauto > pkgs_auto.lst $ apt-mark showmanual > pkgs_manual.lst
2. Restoring
Then at the target machine, with the same or a newer Ubuntu version, we copy the above file lists and restore the packages to add them to the that instance:
$ sudo apt install $(cat pkgs_auto.lst) $ sudo apt install $(cat pkgs_manual.lst)
For example for the the manually added packages in the new environment:
sudo apt install $(cat pkgs_manual.lst)
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package xpdf is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Package musescore is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Package libfluidsynth1 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Unable to locate package google-chrome-stable
E: Package 'libfluidsynth1' has no installation candidate
E: Unable to locate package linux-headers-4.20.0-042000
E: Couldn't find any package by glob 'linux-headers-4.20.0-042000'
E: Unable to locate package linux-headers-4.20.0-042000-generic
E: Couldn't find any package by glob 'linux-headers-4.20.0-042000-generic'
E: Unable to locate package linux-image-unsigned-4.20.0-042000-generic
E: Couldn't find any package by glob 'linux-image-unsigned-4.20.0-042000-generic'
E: Unable to locate package linux-modules-4.20.0-042000-generic
E: Couldn't find any package by glob 'linux-modules-4.20.0-042000-generic'
E: Package 'musescore' has no installation candidate
E: Unable to locate package python-gtk2
E: Package 'xpdf' has no installation candidate
As you can see, some packages may not be possible to install in the new environment due to multiple possible reasons (outdated apt sources, or obsolete packages) so they won’t be available at first, you will have to filter the list by hand until everything goes smooth.
Conclusions
I find particularly useful to have a list of the manual packages at hand, so I can install them in any other computer without missing any functionality int that other environment.
Changelog
- 2021-03-03:
- working solution, tested with Ubuntu 20.04
- fixed the way to install the packages in the new system
- removed the alternative dpkg method
References
- dpkg Ubuntu docs https://help.ubuntu.com/lts/serverguide/dpkg.html
- Advanced Packaging Tool https://en.wikipedia.org/wiki/Advanced_Packaging_Tool
- htorque answer in Restoring all data and dependencies from dpkg –set-selections ‘*’
- Find out IP addresses from MACs in a Local Area NetworkMay 10, 2023
- Choose any key as the modifier in i3wm in 6 stepsJanuary 20, 2021
- Adding a swap memory to Linux from command line in 6 stepsApril 2, 2020
- Free up space in Linux (Ubuntu)March 27, 2020
- Switch between languages in Linux. Write in multiple languages with same keyboard.March 21, 2020
- How to make Ubuntu display emojisFebruary 12, 2020
- Detect and mount USB devices in Linux from consoleJanuary 24, 2019
- How to make screencasts in Ubuntu LinuxJanuary 21, 2019
- Using i3 window manager in LinuxJanuary 7, 2019
- Setting Up A Fresh Linux ServerAugust 25, 2018
- How To Download A Website With Wget The Right WayJune 30, 2017
- Replicate Installed Package Selections From One Ubuntu System To Another
- Using Clamav Antivirus In UbuntuJanuary 25, 2017
- How to Type Spanish Characters, Accents and Symbols in LinuxJune 6, 2016
Ubuntu
- How to activate tap to click touchpad's feature in Ubuntu in 4 stepsMarch 4, 2021
- Difference between suspend and hibernate in Ubuntu and how to execute them from command lineApril 12, 2020
- Solving Google Chrome's gpu-process error message in Ubuntu LinuxJanuary 7, 2019
- Solving Google Chrome's secret service operation error message in Ubuntu LinuxJanuary 7, 2019
- Start Emacs In Ubuntu The Right WayJune 10, 2017
Unix Shell
- Connect to a Bluetooth device from command line in Ubuntu LinuxJune 23, 2020
- Add Infolinks Script To An Existing Website From Console With Sed CommandApril 4, 2017
- How to change all files permissions to 644 and directories to 755January 10, 2017
- Shell Redirect Output And Errors To The Null Device In BashDecember 9, 2016
- Prevent Running Of Duplicate Cron JobsDecember 8, 2016
- Delete All Backup Files Recursively In BashNovember 28, 2016
- Bash Script to Find Out If MySQL Is Running Or NotNovember 9, 2016
Articles
Subcategories
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·