Backup installed packages list in Ubuntu and restore via Synaptic

To backup your Ubuntu install you don’t just need to keep a copy of the /home folder (or partition), since you would still need to re-fetch all the packages you installed, and that can be time consuming, especially if you carefully chose the applications to add to the system.

Synaptic already offers a similar function, which is File > Save Markings As… (be sure to fill the check box “Save full state, not only changes”, otherwise you will be probably getting a 0byte file). You can then use the File > Read Markings function to restore the package list on another system/install.

What’s the deal with this? The function actually saves indiscriminately a list of all the installed packages, including those that were installed just because they were a dependence. For example if you sudo apt-get/aptitude install packagename you will probably install also packagename-data and packagename-core or something along those lines, as they are dependencies of packagename, but the dependencies may be more complex and deeper (for example, packagename-core may also require other packages in turn); dependencies can change over time, so if package A requires package B today, a month from now that may be not true anymore; so if you passively restore the whole packagelist, you would be installing package B even if that’s not needed anymore.

The solution is to save a list of only the “main” packages, which will in turn require the correct dependencies; this can be achieved with:

aptitude search "~i ?not(~M)" -F "%p install" > packagelist.txt

This saves into packagelist.txt the list of the installed packages (~i) that were not installed automatically (not(~M)), mantaining the same format of the list generated by Synaptic, that is “packagename install” in each row, so you can seamlessly import it from Synpatic.

2 thoughts on “Backup installed packages list in Ubuntu and restore via Synaptic”

  1. Saves the file of course but is unclear as to how to reinstall, for example on a new drive.
    Unless I am to inexperienced to understand perhaps :-))

    1. Actually, I wasn’t crystal-clear on this since I gave it as granted, so you’re right, the guide is missing in this part; alas I’m not on Ubuntu now, so I am not able to check the name of the relevant synaptic option, anyway in the same file menu where you find “Save Markings”, there is an equivalent function to do the same, which may be named “Import markings” or somethning on that meaning 😉 Then, you just need to point it to the file you created with this method.

Leave a Reply

Your email address will not be published. Required fields are marked *