SnapOverflow

SnapOverflow Logo SnapOverflow Logo

SnapOverflow Navigation

  • Home
  • Server
  • Ubuntu

Mobile menu

Close
  • Home
  • System Administrators
    • Hot Questions
    • New Questions
    • Tags
  • Ubuntu
    • Hot Questions
    • New Questions
    • Tags
  • Help
Home / ubuntu / Questions / 17823
Accepted
Ivan
Ivan
Asked: 2010-12-17 18:08:49 +0800 CST2010-12-17 18:08:49 +0800 CST 2010-12-17 18:08:49 +0800 CST

How to list all installed packages

  • 772

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 would I do this?

package-management apt
  • 24 24 Answers
  • 4679001 Views

24 Answers

  • Voted
  1. Best Answer
    Sabacon
    2010-12-17T19:02:36+08:002010-12-17T19:02:36+08:00

    Ubuntu 14.04 and above

    The apt tool on Ubuntu 14.04 and above makes this very easy.

    apt list --installed
    

    Older Versions

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

    dpkg --get-selections | grep -v deinstall
    

    (The -v tag "inverts" grep to return non-matching lines)

    To get a list of a specific package installed:

    dpkg --get-selections | grep postgres
    

    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
    

    Alternatively, simply use

    dpkg -l
    

    (you don't need to run any of these commands as the superuser, so no sudo or any other variants necessary here)

    • 2821
  2. intuited
    2012-08-29T13:35:16+08:002012-08-29T13:35:16+08:00

    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, also add the option -F '%p', as mentioned by karthick87.


    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.

    • 490
  3. bcl
    2013-02-03T02:39:47+08:002013-02-03T02:39:47+08:00

    To list all packages intentionally installed (not as dependencies) by apt commands, run the following :

    (zcat $(ls -tr /var/log/apt/history.log*.gz); cat /var/log/apt/history.log) 2>/dev/null |
      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) 2>/dev/null |
      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
    ...
    
    • 251
  4. gogaman
    2012-05-17T10:26:48+08:002012-05-17T10:26:48+08:00

    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
    
    • 208
  5. Tim Tisdall
    2014-07-11T05:43:47+08:002014-07-11T05:43:47+08:00
    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 (though this includes packages that were part of the default initial install) without all of the dependencies included due to these packages being installed.

    To output the result into a text file:

    apt-mark showmanual > list-manually-installed.txt
    
    • 94
  6. kyleN
    2012-05-17T10:40:42+08:002012-05-17T10:40:42+08:00

    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
    
    • 44
  7. karthick87
    2010-12-17T19:35:42+08:002010-12-17T19:35:42+08:00

    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.

    • 42
  8. user.dz
    2015-09-06T15:09:50+08:002015-09-06T15:09:50+08:00

    APT-Clone

    This package can be used to clone/restore the packages on a apt based system.

    • It will save/restore the packages, sources.list, keyring and automatic-installed states.
    • It can also save/restore no longer downloadable packages using dpkg-repack.

    source: man apt-clone

    APT-Clone is used by ubiquity (Ubuntu installer) for upgrade process. It is much better than the dpkg --get-selections solution because:

    1. It preserves all repositories information.
    2. It keeps track of what packages were automatically installed.
    3. It allows to repack locally installed DEB files.

    How to Use

    1. Install

       sudo apt-get install apt-clone
      
    2. Make backup

       sudo apt-clone clone path-to/apt-clone-state-ubuntu-$(lsb_release -sr)-$(date +%F).tar.gz
      
    3. Restore backup

       sudo apt-clone restore path-to/apt-clone-state-ubuntu.tar.gz
      

      Restore to newer release:

       sudo apt-clone restore-new-distro path-to/apt-clone-state-ubuntu.tar.gz $(lsb_release -sc)
      

    Result structure

    It makes a simple gzipped tar file which can be easily edited and reviewed before restoring on the other machines. Here an example of its structure:

    /
    ├── etc
    │   └── apt
    │       ├── preferences.d
    │       ├── sources.list
    │       ├── sources.list.d
    │       │   ├── anton_-ubuntu-dnscrypt-vivid.list
    │       │   ├── maarten-baert-ubuntu-simplescreenrecorder-vivid.list
    │       │   └── megasync.list
    │       ├── trusted.gpg
    │       └── trusted.gpg.d
    │           ├── anton__ubuntu_dnscrypt.gpg
    │           ├── anton__ubuntu_dnscrypt.gpg~
    │           ├── maarten-baert_ubuntu_simplescreenrecorder.gpg
    │           └── maarten-baert_ubuntu_simplescreenrecorder.gpg~
    └── var
        └── lib
            └── apt-clone
                ├── extended_states
                ├── installed.pkgs
                └── uname
    
    • 38
  9. Tamer
    2011-04-13T04:26:16+08:002011-04-13T04:26:16+08:00

    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.

    • 37
  10. Nerdfest
    2010-12-17T20:46:37+08:002010-12-17T20:46:37+08:00

    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.

    • 37

Sidebar

Stats

  • Questions 681965
  • Answers 980273
  • Best Answers 280204
  • Users 287326
  • Popular
  • Answers
  • Marko Smith

    How to add a directory to the PATH?

    • 17 Answers
  • Marko Smith

    How do I install .run files?

    • 7 Answers
  • Marko Smith

    How to list all installed packages

    • 24 Answers
  • Marko Smith

    How do I get the CPU temperature?

    • 21 Answers
  • Marko Smith

    Unable to lock the administration directory (/var/lib/dpkg/) is another process using it?

    • 25 Answers
  • Marko Smith

    How can I add a user as a new sudoer using the command line?

    • 7 Answers
  • Marko Smith

    Change folder permissions and ownership

    • 9 Answers
  • Marko Smith

    How do you restart Apache?

    • 13 Answers
  • Marko Smith

    How can I uninstall software?

    • 11 Answers
  • Marko Smith

    How can PPAs be removed?

    • 26 Answers
  • Martin Hope
    justingrif How to add a directory to the PATH? 2009-07-23 12:42:23 +0800 CST
  • Martin Hope
    NES How to enable or disable services? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan How to list all installed packages 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra Unable to lock the administration directory (/var/lib/dpkg/) is another process using it? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde How to keep processes running after ending ssh session? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B How can I add a user as a new sudoer using the command line? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans How do I remove old kernel versions to clean up the boot menu? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry How do I determine the total size of a directory (folder) from the command line? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher "The following packages have been kept back:" Why and how do I solve it? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford How can PPAs be removed? 2010-07-30 01:09:42 +0800 CST

Related Questions

Trending Tags

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • Home
  • Questions
    • Hot Questions
    • New Questions
  • Tags
  • Help

Footer

SnapOverflow

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Help

© 2022 SOF-TR. All Rights Reserve