Take the 2-minute tour ×
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

15 Answers 15

up vote 317 down vote accepted

To get a list of packages installed locally do this in your terminal:

dpkg --get-selections | grep -v deinstall

To save that list to a text file called packages on your desktop do this in your terminal:

dpkg --get-selections | grep -v deinstall > ~/Desktop/packages

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

share|improve this answer
12  
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
6  
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
74  
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
22  
It's sad and amazing that @intuited 's comment is not better understood by the community. Would the more "highly rated" contributors stop to think more before giving the advice that simply reloading old packages on a new ubuntu version is not a good idea(?). With all the dpkg options I still do not see one that pulls out the 'expressely' installed packages by a user in order that THAT list can be reloaded and allowed to have its dependencies installed; I would love to know it - please share that info. In the meantime, make a list of the packages you really need on a re-install and run that –  Ricalsin Jul 17 '13 at 17:42
15  
We all know that linux discriminates people without photographic memory, but seriously, what would be wrong with apt list installed. Someday we should stop systematically failing the "keep simple things easy" principle. –  nus Nov 19 '13 at 20:31

Create a backup of what packages are currently installed:

dpkg --get-selections > list.txt

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

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 (i.e. to install packages set by dpkg --set-selections)

sudo apt-get dselect-upgrade
share|improve this answer
2  
Great tip about restoring on another machine. +1. –  Drew Noakes Jan 17 '13 at 0:28
11  
sudo is unnecessary to list packages –  Nick T Jul 11 '13 at 21:17
7  
migrating between 2 different ubuntu 12.04 machines this approach broke my system. it took a while until I realized that somehow ubuntu-desktop got uninstalled - probably due to one of the dpkg commands. be careful, it took me hours to repair the damage! –  Karl Frisk Aug 19 '13 at 16:02

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. As pointed by another gertvdijk comment, this problem was fixed and the method is reliable yet again.


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
11  
This should be the correct answer. Why list dependencies? –  Stavros Korokithakis Dec 8 '12 at 1:44
3  
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 '13 at 15:31
    
@gertvdijk: Interesting.. can you provide a link with a more detailed explanation? –  intuited Jan 11 '13 at 15:59
3  
@intuited "Fix Released" for Precise (some time ago). :) –  gertvdijk Jun 20 '13 at 20:10
1  
This lists all packages, not just manually installed packages on Ubuntu 13.10. –  Eamon Nerbonne Oct 31 '13 at 14:33

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:' –  belacq May 17 '13 at 16:16
1  
Does this approach miss packages installed with dpkg?? –  drevicko Jun 13 '13 at 23:27
    
gives nicer results than above answers! –  user01 Feb 22 at 14:34
    
While the above simple answers are good for the general user. This method by far is the best for backtracking all the customizations done to the machine, as it also shows what was removed, or added, from the base image, as it list them in the sequence it was performed, and helps you remember which is the correct sequence to add them back in another system. –  AllGamer Jul 24 at 16:27
    
@AllGamer My only problem is that /var/log/ is a memory mapped directory on my machine, so I cannot use this approach... –  Ali Aug 16 at 20:44

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, right?

If so, it's very easy. You'll need an "Ubuntu Single Sign On account." (Create it before reinstalling so that your system is synced.)

  1. Go to the Software Center and look for the "Sync Between Computers..." option under the File menu.

  2. When 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 to 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.

share|improve this answer
    
I set the same name for my computer on a fresh installation to prevent from huge downloading from Ubuntu One server each time. Do you think that this work for me? –  AliNa Aug 17 '13 at 20:29

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

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

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
    
I am not trying a complete mirror, but only the fact of taking config files into account is awesome. I was looking for such a tool for a while now, thank you very much! –  TiBo Sep 5 at 9:58

There's also a tool called Aptik (both command line and GUI) which can help you view a list of all installed packages, with an option to select/unselect some of them, make a backup list, and then restore the same set of packages in another system.

To install:

sudo add-apt-repository -y ppa:teejee2008/ppa
sudo apt-get update
sudo apt-get install aptik

Further info: http://www.teejeetech.in/2014/04/aptik-v14.html

enter image description here

As can be seen in the screenshot, Aptik lets you also backup and restore PPAs, which will certainly be necessary to install some of the packages installed.

share|improve this answer

There's a great explanation on Unix StackExchange that describes how to use aptitude to list packages not installed as dependencies, and how to compare that list with the list of default packages for your Ubuntu release.

To obtain the manifest file for desktop versions of 12.04 and newer, visit this site, choose your release, and scroll down below the CD images to the files section. You'll find something like "ubuntu-12.04.4-desktop-amd64+mac.manifest" that matches your architecture.

For server versions you'll need to obtain the manifest file from the ISO that was used to install the original system. For a VPS or cloud server, your provider may make the images available or you might need to contact them.

Here's an example using the code from the referenced post, along with modifications to install on the new server.

Old server (code from other post, output saved to file):

aptitude search '~i !~M' -F '%p' --disable-columns | sort -u > currently-installed.list
wget -qO - http://mirror.pnl.gov/releases/precise/ubuntu-12.04.3-desktop-amd64.manifest \
  | cut -f1 | sort -u > default-installed.list
comm -23 currently-installed.list default-installed.list > user-installed.list

On the new server, copy the file using scp, then use sed to append 'install' to every line (-i performs an inline-replace). Then you can use the list as input to 'dpkg --set-selections' and install the packages with apt-get:

scp user@oldserver:user-installed.list .
sed -i 's/$/\tinstall/' user-installed.list
sudo dpkg --set-selections < user-installed.list
sudo apt-get dselect-upgrade

Before starting this task, I recommend reading and understanding all parts of the post mentioned in the beginning, and then consult the aptitude reference guide for details on search patterns.

share|improve this answer

For the complete rundown see:

https://help.ubuntu.com/community/SwitchingToUbuntu/FromLinux/RedHatEnterpriseLinuxAndFedora#Command_Line_Tools

half way across the page:

dpkg --list

share|improve this answer

you can look at the apt log under /var/log/apt/ the dpkg log under /var/log/

and you can get the list of the installed packages with just a command:

dpkg -l | grep ii
share|improve this answer
apt-mark showmanual

man pages state:

will print a list of manually installed packages

So, it should just give a list of explicitly installed packages without all of the dependencies included due to these packages being installed.

share|improve this answer

The below command will also lists all the installed packages,

grep ' installed ' /var/log/dpkg.log /var/log/dpkg.log.1 | awk '{print $5}' | sort -u
share|improve this answer

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.