How-To Geek
Show the List of Installed Packages on Ubuntu or Debian
While working on the instructions for compiling MonoDevelop from source, I relied heavily on the dpkg and apt-cache commands to tell me what was already installed vs what packages were available in the repository. After completing that article it occurred to me that I should explain how to show what packages are currently installed… so here we are.
The command we need to use is dpkg –get-selections, which will give us 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
The full list can be long and unwieldy, so it’s much easier to filter through grep to get results for the exact package you need. For instance, I wanted to see which php packages I had already installed through apt-get:
dpkg --get-selections | grep phplibapache2-mod-php5 install php-db install php-pear install php-sqlite3 install php5 install php5-cli install php5-common install php5-gd install php5-memcache install php5-mysql install php5-sqlite install php5-sqlite3 install php5-xsl install
For extra credit, you can find the locations of the files within a package from the list by using the dpkg -L command, such as:
dpkg -L php5-gd /. /usr /usr/lib /usr/lib/php5 /usr/lib/php5/20060613 /usr/lib/php5/20060613/gd.so /usr/share /usr/share/doc /etc /etc/php5 /etc/php5/conf.d /etc/php5/conf.d/gd.ini /usr/share/doc/php5-gd
Now I can take a look at the gd.ini file and change some settings around…
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (25)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 10/8/07




Very informative, well written….you have been bookmarked.
Cheers,
Thomas
Just joined and have a lot to learn.
I think I’ve picked the right place. Cheers KiwiDon.
I cannot get sound, or printer, capability, from desktop computer, since Windows Vista had been installed. How can this problem be corrected?
@Glen Wolters: It’s possible you need drivers for those things. Post your question on the forums along with your computer’s make and model number, printer make and model number and we will try to help you find drivers to fix those things.
Right you are that the complete list long. In fact, mine was well beyoun a single page.
What is odd is that I could only scroll through the list from the end up through part of the lib*, but no farther. I really wanted to review what all was already installed. But I hit a brick wall.
Can anyone tell me why this would be?
I imagine that if I experiment with pipe-grep-letter -* I may be able to see alphabetic lists…
fastbullet, its not elegant but in a pinch you can redirect anything to a file. (Use greater than > redirect parm)
dpkg –get-selection > dkpg-get.txt
That will give you a text file that you can view.
You are probably aware of adding the | (pipe) more options on any command, granted that will not let you scroll back and forth.
dpkg –get-selection | more – no scrolling, but you can see everything from beginning to end.
You will quickly want to learn about grep and awk…just search the terms for plenty of helps. Using grep I can search for any lines that contain a string of characters, for instance if I wanted to find all instances of open* (openssh and openoffice.org3 come to mind and you will probably have a few more). The command with grep would look as follows:
dpkg –get-selection | grep open*
That should get you going and give you some additional terms to search for and use. You can get by with grep, but if you really want to do allot, learn shell scripting (bash (Borne shell) and korn (Korn shell) are the most popular, csh (C shell) is another good one, rarely used except by old school system administrators. Ultimately if you really want to manipulate the output of your commands you will want to learn AWK.
Welcome to GNU/Linux and enjoy the journey, I know you will!
Endless thanks !!
On the same topic, copying packages from one machine to another:
On source machine:
dpkg –get-selection | grep -v deinstall > dkpg-get.txt
On target machine:
dpkg –clear-selections
dpkg –set-selections
Ooops, it had to be:
#source machine:
dpkg –get-selection | grep -v deinstall > dkpg-get.txt
#target machine:
dpkg –clear-selections
dpkg –set-selections
apt-get dselect-upgrade
(You may need to copy /etc/apt/sources.list from source machine to target to let apt-get to download the packages beforehand)
dpkg –set-selections
It looks like forum has problems with the firefox?
dpkg –set-selections
.. The ‘less’ sign and the text after it got cut, I’ll rephrase:
cat dkpg-get.txt | dpkg –set-selections
Cheers body,
it was very useful :-)
Cheers! Was searching for this helpful document!
Oh ! very useful, and thank you very much.
very useful and thanks a lot geeks
Is there a way to expand this to get package descriptions as well? I know that /lib/dpkg/available has a list of all available packages from the last apt-get update with their descriptions. I want to figure out a way to generate a document showing which new packages have been added along with their descriptions to document what has changed on my system. (lenny 5.0.2).
I thought there was a way to (somehow!) list only the non-default packages – i.e. the ones added after an initial install. Any clues?
@Donald:
to get package descriptions as well use dpkg-query which will gives name,version,description by default but can be customized using dpkg-query -f to show all kinds of things, see man dpkg-query
You can also use:
dpkg -l
or
dpkg –list
or
dpkg-query -l
or
dpkg-query –list
This is useful to get more informations about installed packages.
You know, this article is over two years old, and yet its still useful. I needed this information today for a project. Thanks for writing it!
Thank you very much to all!
Thanks-a-lot. and keep up the good work.
Hello All,
Could anybody kindly tell me how to upgrade a particular installed software?
for instance, i have installed HAproxy (version 1.3) on ubuntu 10.04 and now i want to upgrade it to version 1.4.
i have installed HAproxy using terminal command ‘apt-get install haproxy’
any help here please?
Regards
thanks frenzy you can also try
ls -f
ls -a