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)

Loading... Logging you in...
  • Logged in as
If you don't use /etc as a destination, you won't need to run this command as root. Since you are only creating this list to copy it to another computer, there is no need to put it in /etc.
Call me Mr Obvious here, but now's also a good time, if you haven't already, to create a seperate home partition and move your /home directory there.

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.
I agree. Saving this to the separate /home would be wiser.

Also, thanks for posting this AFTER I move to 8.04. :P
Oropher8598's avatar

Oropher8598 · 882 weeks ago

Doesn't this method end up including a slew of stuff that's been updated or replaced in the new OS version?

Also, for the terminal-unsavvy out there, you didn't include the command to install everything on the package list.
Curious, Does this also remove packages not listed in the package list?

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
I would consider myself to be "terminal-unsavvy", I get "Permission Denied" when I try to run this command.
Awesome, thanks
I'm a beginner, I already ran "sudo apt-get dselect-upgrade" however, when I run "sudo dpkg --get-selections > /etc/package.selections" or "sudo dpkg --set-selections < /etc/package.selections && apt-get dselect-upgrade" I get an error back saying "-bash: /etc/package.selections: permission denied". Thanks for the Help.

.
Never Mind, I created the file by using "touch" and than used "chmod" to set permissions. THANKS!
I have two PC (same configuration) installing Ubuntu Hardy Heron. An PC (PC A) died (Ubuntu could not start) but all of files is existing now. On this PC, I installed many valuable application. I want to move installed packages of PC A to another (PC B) to use (I want to save bandwidth - don't want to use apt-get install all time). What should I do?
This is great! This is exactly what I was looking for. When something crashes a PC badly, I like to do a fresh install and then restore the package, which to this moment I had to remember as I saw the list. This will simplify that process greatly!

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
a question: how to save only the manually installed packages? that sounds wiser, considering fact that someone might be doing release upgrade.

Post a new comment

Comments by

Clicky Web Analytics