Howto: Restore All Installed packages in Ubuntu Hardy Heron and to a New machine
Ever forget what you had installed and find yourself at a fresh ubuntu install thinking to yourself... Damn now I gotta open up synaptic and search for everything I had... Well fortunately you dont need to do that. With this easy howto you can also restore all your packages that were installed by simply creating a package list and uninstalling every application installed after the list was made.
Lets get started shall we?
The following command creates a list of all the installed packages at the present time:sudo dpkg --get-selections > /etc/package.selections
Now we created our package list and we can copy this list to a new ubuntu computer and install the same packages in the list to the new machine or, restore the packages to the time you created the package list:sudo dpkg --set-selections < /etc/package.selections && apt-get dselect-upgrade
The above command will uninstall all packages installed after you created your restore list.
Comments (13)

Comments by IntenseDebate
menachem · 882 weeks ago
ageispolis 0p · 882 weeks ago
Also, if you put your package list in /etc as outlined here, it would disappear when you install, as the root partition gets formatted by default.
Dan · 882 weeks ago
Also, thanks for posting this AFTER I move to 8.04. :P
Oropher8598 · 882 weeks ago
Also, for the terminal-unsavvy out there, you didn't include the command to install everything on the package list.
Bradford Knowlton 2p · 881 weeks ago
For example if I take and remove packages, such as Gnome games, would this remove them when I run apt-get dselect-upgrade?
Also Oropher8598, For the terminal-unsavvy like yourself, the following command does the package installation:
"apt-get dselect-upgrade"
&& tells it to run both commands, 1 after another
So this line runs them both in order, as explained in the post:
"sudo dpkg --set-selections < /etc/package.selections && apt-get dselect-upgrade"
Thanks,
Bradford Knowlton
http://x86Virtualization.com
Ken · 881 weeks ago
AnRkey · 871 weeks ago
PiP · 869 weeks ago
.
PiP · 869 weeks ago
SuperThin · 862 weeks ago
Nelson · 850 weeks ago
On putting it on /etc: I think this is a good practice, because the package.selections could be considered a "configuration" file. Then under good practices, you should be backing up your entire /etc folder somewhere else for restores.
On sudo problems: To execute the first command without permission denied, I changed the command a little bit to this:
sudo dpkg --get-selections | sudo tee /etc/package.selections
The program tee reads from standard input (which is being redirected here with |) and writes to the file passed as parameter. By calling tee with sudo, then it has access to write inside /etc
Bartek · 828 weeks ago