Restoring Installed Packages in Debian

I have an older laptop that runs Ubuntu Linux and one of the issues that comes up regularly is that Ubuntu releases a new version every 6 months and I usually flatten the disks on that machine and do a fresh install. The base system is great and very usable, but there are several packages that I install manually after the fact, most of them being programming tools. There is a quick way for you to list out all installed packages and then restore them after upgrading and I will cover that technique here.

Note: The instructions listed here are for Debian based distributions that use .deb based packages.

Backing up a list of installed packages

In order to list out all installed packages and save them to a text file, you can do this from the shell:

$ dpkg --get-selections > installed-packages.txt

Let's deconstruct the above command:

  • dpkg is the Debian package manager
  • --get-selections is the parameter or action that lists all the currently installed packages. You can also pass a pattern to this action to generate different types of package lists. Look at the man pages for details.
  • > textfilename.txt will redirect the standard output to the text file specified.

Restoring the list of installed packages

When you need to restore the installed packages from a previous state, you can run the following command from the shell:

$ dpkg --set-selections < installed-packages.txt

The command above is a little different and those differences mean:

  • --set-selections is the action that sets the package selections using a file read in from standard in.
  • < textfilename.txt will read the contents of the file and send them to standard in.

Conclusion

Backing up and restoring your package installation list is a really simple procedure in Debian based distributions. You can even script it out and run it on a schedule and then save it to a cloud storage service such as Dropbox. Let me know what you think and if you have a better process.

Comments

Comments powered by Disqus