Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I export a list of installed Debian packages on a system, and then install those same packages on a new system?

share|improve this question
up vote 12 down vote accepted

To backup:

sudo dpkg --get-selections > /tmp/dpkglist.txt

To Restore:

sudo dpkg --set-selections < /tmp/dpkglist.txt
sudo apt-get -y update
sudo apt-get dselect-upgrade

Also see this question for additional options and info: http://serverfault.com/questions/737/ubuntu-how-to-setup-a-new-machine-like-an-existing-one

I have the above running in a daily cronjob that checks the dpgklist into SVN as part of our server inventory. This will allow you to keep a reasonable accurate inventory of installed packages across your servers and its easy to do a quick side-by-side diff to see if a server is missing a particular package.

share|improve this answer

aptitude also satisfies this usecase, and it preserves information about "automatically installed" packages that other methods do not. Run the following on the reference machine:

aptitude search -F '%p' '~i!~M' > package_list 

Copy package_list to the other machine and run

xargs aptitude --schedule-only install < package_list; aptitude install; 
share|improve this answer
    
Just a minor note. According to the aptitude reference manual, the "package" field is "expandable" by default, so aptitude search -F '%p' '~i!~M' > package_list should also work fine. – chronos Oct 17 '13 at 23:34
    
Regarding package backup: see plug for deborphan @ bogdan.org.ua/2013/10/18/… – TomRoche Nov 17 '15 at 5:43
    
[insert your own linebreaks, since http://serverfault.com/editing-help#linebreaks lies] Regarding package restore: this will need to be done as root, no? If so,<br/> The xargs in your restore commandline= xargs aptitude --schedule-only install < package_list; aptitude install; makes me want to know,<br/> 1. Why does aptitude need the xargs? dpkg --set-selections doesn't.<br/> 2. Presuming aptitude does need the xargs, where to put one or more sudos in your restore commandline? Or otherwise get root for running that line, presuming that's necessary. – TomRoche Nov 17 '15 at 6:00

That's a good idea, and you might also set up one server with apt-proxy if you make a habit of this.

share|improve this answer
    
After playing around with several proxies for apt, I ended up deciding on apt-cacher-ng. apt-cacher-ng is very simple to setup and from several accounts it seems to be more robust than the original apt-proxy. Each person has their own favourite though. unix-ag.uni-kl.de/~bloch/acng – faultyserver Aug 20 '09 at 21:06
    
My vote is for approx, it's the only one that isn't some kind of insane. – womble Aug 20 '09 at 23:08
    
Interesting... I've not actually tried any of the alternatives. – user17642 Aug 21 '09 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.