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
$ 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
OR
$ sudo apt-get install -y $(
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}')
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 5 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
if you have aptitude installed, this works as a search
aptitude search ‘~i ‘
that said, i prefer the solutions already listed
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
I’m using this for years:
I’ve come across a TON of tutorials on this subject that seem to leave out the method for cleaning up the output file for parsing.
For the section:
How to save a list to a text file
The syntax is as follows on server1:
$ dpkg --get-selections | grep -v deinstall > mylist.txt
This ends up giving you a text file formatted like this:
…
tcpdump install
tdb-tools install
telnet install
time install
zlib1g:amd64 install
…
You will get gripes about “install” not being a package in APT if you skip straight to using:
sudo apt-get install -y $(< mylist.txt)
You need to get rid of all the tabs, newline chars and properly space the text of the list first. There may also be a difference in platform such as amd64 vs i386.
To do that, I'm a fan of this Perl5 one-liner:
perl -pe 's/\s*install\n|\:amd64/ /g' mylist.txt > mylist.txt
This tweaks the file to look like this instead, which will actually work with that final step using "apt-get install -y" :
... tcpdump tdb-tools telnet time zlib1g ...
Thanks for adding your notes. I appreciate your post.