The syntax for dpkg may have changed slightly since 2006 because that command didn't work for me, @koanhead. sudo dpkg --set-selections < ~/Desktop/packages && sudo apt-get -u dselect-upgrade does the trick.
–
JamesFeb 17 '11 at 20:44

109

Note that this won't keep track of which packages were explicitly installed by the user and which were installed as dependencies. This means that if you use this method to recreate your setup on another machine, apt won't be able to remove unneeded dependencies when you remove a given package.
–
intuitedAug 28 '12 at 21:03

32

It's sad and amazing that @intuited 's comment is not better understood by the community. Would the more "highly rated" contributors stop to think more before giving the advice that simply reloading old packages on a new ubuntu version is not a good idea(?). With all the dpkg options I still do not see one that pulls out the 'expressely' installed packages by a user in order that THAT list can be reloaded and allowed to have its dependencies installed; I would love to know it - please share that info. In the meantime, make a list of the packages you really need on a re-install and run that
–
RicalsinJul 17 '13 at 17:42

33

We all know that linux discriminates people without photographic memory, but seriously, what would be wrong with apt list installed. Someday we should stop systematically failing the "keep simple things easy" principle.
–
nusNov 19 '13 at 20:31

This should be the answer, but using aptitude is a bit unreliable because of Multiarch currently (fixes on the way), unfortunately. Still +1 for pointing out only listing explicitly installed packages and a way to do this (despite it won't work on 11.10+ currently).
–
gertvdijkJan 11 '13 at 15:31

@gertvdijk: Interesting.. can you provide a link with a more detailed explanation?
–
intuitedJan 11 '13 at 15:59

migrating between 2 different ubuntu 12.04 machines this approach broke my system. it took a while until I realized that somehow ubuntu-desktop got uninstalled - probably due to one of the dpkg commands. be careful, it took me hours to repair the damage!
–
Karl FriskAug 19 '13 at 16:02

While the above simple answers are good for the general user. This method by far is the best for backtracking all the customizations done to the machine, as it also shows what was removed, or added, from the base image, as it list them in the sequence it was performed, and helps you remember which is the correct sequence to add them back in another system.
–
AllGamerJul 24 '14 at 16:27

@AllGamer My only problem is that /var/log/ is a memory mapped directory on my machine, so I cannot use this approach...
–
AliAug 16 '14 at 20:44

You can use Synaptic to save the current state of your installed packaged. In Synaptic, select "file/save markings", Enter the name of the file to save the state to, and make sure to check the "Save full state, not only changes" box.

The file saved from this can be loaded into a new machine using "file/read markings" in Synaptic.

I recommend using blueprint. Even though it is designed for servers, it can be also used from desktops as well. It will create a shell script/chef/puppet that you ca use to re-install all you packages.

There's also a tool called Aptik (both command line and GUI) which can help you view a list of all installed packages, with an option to select/unselect some of them, make a backup list, and then restore the same set of packages in another system.

There's a great explanation on Unix StackExchange that describes how to use aptitude to list packages not installed as dependencies, and how to compare that list with the list of default packages for your Ubuntu release.

To obtain the manifest file for desktop versions of 12.04 and newer, visit this site, choose your release, and scroll down below the CD images to the files section. You'll find something like "ubuntu-12.04.4-desktop-amd64+mac.manifest" that matches your architecture.

For server versions you'll need to obtain the manifest file from the ISO that was used to install the original system. For a VPS or cloud server, your provider may make the images available or you might need to contact them.

Here's an example using the code from the referenced post, along with modifications to install on the new server.

On the new server, copy the file using scp, then use sed to append 'install' to every line (-i performs an inline-replace). Then you can use the list as input to 'dpkg --set-selections' and install the packages with apt-get: