≡ Menu

How to get list of installed packages on Ubuntu / Debian Linux

I am a new Ubuntu Linux sysadmin. How do I get a list of all installed packages on server1 and install those on server2? How to list all installed packages using apt-get command on Ubuntu or Debian server?

You need to use dpkg and other commands as follow to see a list of all installed packages on Ubuntu or Debian Linux server.

Just list all installed packages with a short description

Type the following command:
$ dpkg-query -l
Sample outputs:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                          Version                           Architecture Description
+++-=============================-=================================-============-=============================================================================
==
ii  accountsservice               0.6.40-2ubuntu11.3                amd64        query and manipulate user account information
ii  acct                          6.5.5-2.1ubuntu1                  amd64        The GNU Accounting utilities for process and login accounting
ii  acl                           2.2.52-3                          amd64        Access control list utilities
ii  adduser                       3.113+nmu3ubuntu4                 all          add and remove users and groups
ii  apparmor                      2.10.95-0ubuntu2.5                amd64        user-space parser utility for AppArmor
ii  apt                           1.2.19                            amd64        commandline package manager
ii  apt-transport-https           1.2.19                            amd64        https download transport for APT
ii  apt-utils                     1.2.19                            amd64        package management related utility programs
ii  atop                          1.26-2build1                      amd64        Monitor for system resources and process activity
ii  base-files                    9.4ubuntu4.3                      amd64        Debian base system miscellaneous files
ii  base-passwd                   3.5.39                            amd64        Debian base system master password and group files
ii  bash                          4.3-14ubuntu1.1                   amd64        GNU Bourne Again SHell
ii  bash-completion               1:2.1-4.2ubuntu1.1                all          programmable completion for the bash shell
ii  bc                            1.06.95-9build1                   amd64        GNU bc arbitrary precision calculator language
ii  bind9-host                    1:9.10.3.dfsg.P4-8ubuntu1.4       amd64        Version of 'host' bundled with BIND 9.X
ii  bsdmainutils                  9.0.6ubuntu3                      amd64        collection of more utilities from FreeBSD

Just want to see a list of packages only? Try:
$ dpkg-query -f '${binary:Package}\n' -W
Sample outputs:

unattended-upgrades
update-manager-core
ureadahead
usbutils
util-linux
uuid-runtime
vim
vim-common
vim-runtime
vim-tiny
virt-what
vnstat
wamerican
wbritish
wget
whiptail
whois
xauth
xdg-user-dirs
xkb-data
xml-core
xz-utils
zlib1g:amd64

How to get a list of packages installed

Type the following command
$ dpkg --get-selections | grep -v deinstall
Sample outputs:

Fig.01: Show a list of packages installed

Fig.01: Show a list of packages installed


Another option is to use apt command as follows:
$ apt list --installed
OR just search all php based packages using grep command:
$ apt list --installed | grep php
Sample outputs:

Listing...
accountsservice/xenial-updates,now 0.6.40-2ubuntu11.3 amd64 [installed,automatic]
acl/xenial,now 2.2.52-3 amd64 [installed,automatic]
adduser/xenial,xenial,now 3.113+nmu3ubuntu4 all [installed]
apparmor/xenial-updates,now 2.10.95-0ubuntu2.5 amd64 [installed]
apt/xenial-updates,now 1.2.19 amd64 [installed]
apt-transport-https/xenial-updates,now 1.2.19 amd64 [installed]
apt-utils/xenial-updates,now 1.2.19 amd64 [installed]
atop/xenial,now 1.26-2build1 amd64 [installed]
base-files/xenial-updates,now 9.4ubuntu4.3 amd64 [installed]
base-passwd/xenial,now 3.5.39 amd64 [installed]
bash/xenial-updates,now 4.3-14ubuntu1.1 amd64 [installed]
bash-completion/xenial-updates,xenial-updates,now 1:2.1-4.2ubuntu1.1 all [installed]
bc/xenial,now 1.06.95-9build1 amd64 [installed]
bind9-host/xenial-updates,xenial-security,now 1:9.10.3.dfsg.P4-8ubuntu1.4 amd64 [installed]
bsdmainutils/xenial,now 9.0.6ubuntu3 amd64 [installed]
bsdutils/xenial-updates,now 1:2.27.1-6ubuntu3.2 amd64 [installed]
busybox-initramfs/xenial,now 1:1.22.0-15ubuntu1 amd64 [installed]
busybox-static/xenial,now 1:1.22.0-15ubuntu1 amd64 [installed]
bzip2/xenial,now 1.0.6-8 amd64 [installed]
ca-certificates/xenial,xenial,now 20160104ubuntu1 all [installed]
command-not-found/xenial-updates,xenial-updates,now 0.3ubuntu16.04.2 all [installed]
command-not-found-data/xenial-updates,now 0.3ubuntu16.04.2 amd64 [installed]
console-setup/xenial-updates,xenial-updates,now 1.108ubuntu15.2 all [installed]
console-setup-linux/xenial-updates,xenial-updates,now 1.108ubuntu15.2 all [installed]
.....
..
...
xkb-data/xenial,xenial,now 2.16-1ubuntu1 all [installed]
xml-core/xenial,xenial,now 0.13+nmu2 all [installed,automatic]
xz-utils/xenial,now 5.1.1alpha+20120614-2ubuntu2 amd64 [installed,automatic]
zlib1g/xenial,now 1:1.2.8.dfsg-2ubuntu4 amd64 [installed]

How to save a list to a text file

The syntax is as follows on server1:
$ dpkg --get-selections | grep -v deinstall > mylist.txt
Or
$ dpkg -l | grep ^ii | awk ‘{ print $2}’ > mylist.txt
Now copy mylist.txt to server named server2:
$ scp mylist.txt user@server2:~/

How to restore a list on server2

On server2 restore installations from the mylist.txt, run:
$ dpkg --clear-selections
$ sudo dpkg --set-selections < mylist.txt

OR
$ sudo apt-get install -y $(< mylist.txt)
Finally run the following command to remove unwanted packages:
$ sudo apt-get autoremove
Above command should restore/install packages from backups or another server. Another option is to use aptitude command as follows:

### Create the list of software to a file called /tmp/packages.txt ###
dpkg --get-selections > /tmp/packages.txt
 
### copy file to another server called server1.cyberciti.biz ##
scp /tmp/packages.txt user@server1.cyberciti.biz:/tmp/
 
### Now that your list is copyied use apt-get/synaptic to install the packages###
 
# 1. Login to another server
ssh root@server1.cyberciti.biz
 
# 2. Restore it 
aptitude install $(cat /tmp/packages.txt | awk '{print $1}')
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 3 comments… add one }
  • zasu pitts February 7, 2017, 1:30 pm

    if you have aptitude installed, this works as a search
    aptitude search ‘~i ‘

    that said, i prefer the solutions already listed

  • Ariel February 7, 2017, 3:42 pm

    Alternative:
    ( zcat $( ls -tr /var/log/apt/history.log*.gz ) ; cat /var/log/apt/history.log ) | grep apt-get | grep install

    It is not perfect but always worked fine for me.
    cheers

  • jang February 9, 2017, 9:42 am

    I’m using this for years:

    $ cat /usr/local/bin/apt-list 
    #!/bin/bash
    
    dpkg --get-selections | grep $1 | grep -v deinstall
Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , ,