Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to output a list of all installed packages into a text file, so that I can review it and bulk-install on another system. How to do this?

share|improve this question

10 Answers

up vote 63 down vote accepted

To get a list of packages installed locally and save as a text file called packages on your desktop do this in your terminal:

dpkg --get-selections > ~/Desktop/packages

(you don't need to run this as the superuser, so no "sudo")

share|improve this answer
I use this all the time to migrate people from one PC to another. – Michael Trausch Dec 17 '10 at 3:54
5  
Then, when installing to the new computer, do cat ~/Desktop/packages > sudo dpkg --set-selections && sudo apt-get dselect upgrade source – koanhead Dec 17 '10 at 5:51
1  
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. – James Feb 17 '11 at 20:44
12  
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. – intuited Aug 28 '12 at 21:03

Create a backup of what packages are currently installed:

sudo dpkg --get-selections > list.txt

Then (on another system) restore installations from that list:

sudo dpkg --clear-selections
sudo dpkg --set-selections < list.txt

To get rid of stale packages

sudo apt-get autoremove

To get installed like at backup time

sudo apt-get dselect-upgrade
share|improve this answer
1  
Great tip about restoring on another machine. +1. – Drew Noakes Jan 17 at 0:28

The command you need is dpkg --get-selections, which will give you a list of all the currently installed packages.

$ dpkg --get-selections
adduser                                         install
alsa-base                                       install
alsa-utils                                      install
apache2                                         install
apache2-mpm-prefork                             install
apache2-utils                                   install
apache2.2-common                                install
apt                                             install
apt-utils                                       install
share|improve this answer
Why my answer was edited? It have all the informations needed. – Subv3rsion May 16 '12 at 18:22
3  
Try to keep answers constrained to what the question asks. Using dpkg to find where files are located isn't relevant to what the OP is asking for. For example, you would not talk about how to use the Software Center to audit installation history in a question that asks where to get application reviews. Otherwise your answer becomes a "RTFM Learn everything about this piece of software" post, which Stack Exchange sites strive not avoid – Jacob Johan Edwards May 16 '12 at 18:24
1  
i don't agree with you. With your justification i think answer will no be complete. sorry ... – Subv3rsion May 16 '12 at 18:26
2  
Then please name what part of the question where the OP needs to filter for PHP packages. Or what part of his question requires he knows where the install location of PHP files are. – Jacob Johan Edwards May 16 '12 at 18:27
dpkg --get-selections lists some packages that are not actually installed (and have the 'deinstall' flag). For example, anthy-common on my system: $ dpkg --get-selections | grep anthy-common anthy-common deinstall $ apt-cache policy anthy-common anthy-common: Installed: (none) ... – kyleN May 16 '12 at 18:37

To get just the packages which were expressly installed (not just installed as dependencies), you can run

aptitude search '~i!~M'

This will also include a brief description, which you may want. If not, use the option -F '%p', as mentioned by karthick87.

caveat: as pointed out by gertvdijk in the comments, aptitude is not currently (as of 2013-01-11) considered reliable. This applies to releases starting with 11.10. Our not-thoroughly-informed consensus seems to be that it will most likely work properly for the purposes of this question, but that you should nonetheless be wary until the fix works its way into active Ubuntu releases.


Yet another option seems to be to copy the file /var/lib/apt/extended_states, which is a text file database in this format:

Package: grub-common
Architecture: amd64
Auto-Installed: 0

Package: linux-headers-2.6.35-22-generic
Architecture: amd64
Auto-Installed: 1

Auto-Installed: 0 indicates that the package was expressly installed and is not just a dependency.

share|improve this answer
1  
This should be the correct answer. Why list dependencies? – Stavros Korokithakis Dec 8 '12 at 1:44
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). – gertvdijk Jan 11 at 15:31
@gertvdijk: Interesting.. can you provide a link with a more detailed explanation? – intuited Jan 11 at 15:59
@gertvdijk: any idea how reliable the second method is (using /var/lib/apt/extended_states)? – intuited Jan 11 at 16:01
@gertvdijk: from what's written in this bug report, it doesn't sound like there would be problems using aptitude to dump the system state. – intuited Jan 11 at 16:17
show 1 more comment

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.

share|improve this answer

you want to reinstall the packages now there on 12.04 rite?

if so,its very easy.

  1. Go to the Software Center and and see the option of SYNC BETWEEN COMPUTERS option under the file menu.

  2. As you click on it you will see your computer registered and a list of all apps on your computer

  3. When you will install fresh,that computer will be considered a new computer.

  4. You just have to sign in in your ubuntu account and your previous computer will be shown.

  5. Click on it,you'll get a list of all apps.Select install on the app you want to install.

PS:For this you need a "SINGLE SIGN ON UBUNTU ACCOUNT"(b4 reinstalling create it so that your pc is syncd)

share|improve this answer

To list all packages intentionally installed by apt commands, run the following :

( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep '^Commandline:'

This provides a reverse time based view, with older commands listed first:

Commandline: apt-get install k3b
Commandline: apt-get install jhead

Installation data also showing synaptic usage, but without details (the same with installation date) :

( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; \
cat /var/log/apt/history.log ) | egrep '^(Start-Date:|Commandline:)' | grep -v aptdaemon | egrep -B1 '^Commandline:'

providing the following:

Start-Date: 2012-09-23  14:02:14
Commandline: apt-get install gparted
Start-Date: 2012-09-23  15:02:51
Commandline: apt-get install sysstat
share|improve this answer
Or (with zgrep and removing update messages): zgrep -hE '^(Start-Date:|Commandline:)' $(ls -tr /var/log/apt/history.log*.gz ) | egrep -v 'aptdaemon|upgrade' | egrep -B1 '^Commandline:' – belacqua 2 days ago

To list all installed packages,

dpkg -l |awk '/^[hi]i/{print $2}' > 1.txt
or
aptitude search -F '%p' '~i' > 1.txt
or
dpkg --get-selections > 1.txt

Note:
You will get the result 1.txt file in your home folder.Or you can specify your own path.

share|improve this answer
Could someone show me how to verify my XOrg version number? Thanks. – n00b Dec 29 '12 at 23:02

dpkg-query (instead of dpkg --get-selections, which lists some packages that are not installed) as follows:

dpkg-query -W -f='${PackageSpec} ${Status}\n' | grep installed |  sort -u | cut -f1 -d \ > installed-pkgs

Or:

$ dpkg -l | grep ^ii | sed 's_  _\t_g' | cut -f 2 > installed-pkgs
share|improve this answer

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.

share|improve this answer
blueprint is awesome! very thankfull – Felipe Alcacibar Oct 11 '12 at 15:21

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.