How to Save a List of Installed Packages and Reinstall the Packages Later
by Jiang Yio on Oct.24, 2007, under Computing
(This tutorial will work for any Debian-based system, including Ubuntu.)
If you’ve ever wanted to save a list of software installed on a Debian box so that you could reinstall them later or on a different machine, this is how you do it. I’ve recently had to reinstall my system from scratch, and the following may help you as well.
Generate the Package List
Let’s first save the current package selection states:
$ dpkg --get-selections | grep -v deinstall > packagelist
Now we have a compact list of installed packages in a file called “packagelist”. Let’s store this so that we could retrieve it from our other Debian installation. Or we could email it to ourselves using mailx:
$ cat packagelist | mailx -s “packagelist” user@example.com
Reinstall the Packages
To restore our packages, let’s first restore the package selection states:
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo dpkg --set-selections < packagelist
Now let’s actually install it all:
$ sudo apt-get -u dselect-upgrade
Restore the System
What if we wanted to restore our system to an earlier state by installing everything that’s on our list and uninstalling everything that’s not? We can do that too, but we need to be careful because this may entail a radical change. Before restoring our package selection states, we’re going to deselect every package, thereby marking them for uninstallation:
$ sudo dpkg --clear-selections
$ sudo dpkg --set-selections < packagelist
Now, every package not on our list has been deselected and everything on our list has been selected. Let’s commit the changes:
$ sudo apt-get -u dselect-upgrade
If we wanted to remove the configuration files of the uninstalled packages, we’d do the following instead:
$ sudo apt-get -u dselect-upgrade --purge
Please don’t forget to restore the package selection states before running apt-get, or the whole system would be uninstalled.
I hope this tip proves to be helpful!
July 1st, 2008 on 12:30 am
It doesnt work on Xubuntu
July 1st, 2008 on 1:28 am
Ah, yes. Wordpress screws with double-hyphens and quotation marks. I’ve hacked the post to fix the double-hyphens, but the quotation marks are still weird.
July 5th, 2008 on 2:15 pm
Maybe you should change the theme or modify it
July 5th, 2008 on 3:51 pm
It’s not a problem with the theme, but Wordpress itself. I guess this calls for a plugin or something.