Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

At our university we can get almost any ubuntu package installed we want, but we are not superusers ourselves (we need to request packages being installed).

With some libraries it is not always easy to know whether the package is already installed or not. Is there a simple way/command to check this?

share|improve this question
up vote 40 down vote accepted
apt-cache policy <package name>
share|improve this answer
It's important to know that it supports tab completion in the package name. So it's quite useful even when you don't know the exact package name. – Javier Rivera Aug 23 '10 at 16:28

I always just use this from the command line:

dpkg -l | grep mysql

so the above asks dpkg to list all the installed packages and then I grep for only those that have mysql in the name.

share|improve this answer
dpkg -l "*mysql*" also works and does not hide the explanatory lines in the output. – Philipp Wendler Aug 9 '12 at 15:37

One more variant, using aptitude this time:

aptitude show <package>

Tab completion works here as well.

share|improve this answer

You can use dselect. It provides non-su readonly access.

Also, dpkg -s provides a lot of details related to a package. Eg"

userme:~$ dpkg-query -s sl
Package: sl
Status: unknown ok not-installed
Priority: optional
Section: games
share|improve this answer
This is also available as just dpkg -s . And conversely, dpkg-query -l works just as well as dpkg -l or dpkg --list – belacqua Feb 9 '11 at 8:35

You may use dpkg-query -s <package> 2>/dev/null | grep -q ^"Status: install ok installed"$ in scripts, since it returns exit code 1, if the <package> is not installed, and 0 if the <package> is installed.

share|improve this answer
Be careful: If dpkg -s returns 0, it doesn't necessarily mean that the package is fully/correctly installed. dpkg -s also returns 0 if the package is in half-configured or in config-files state (and I guess also in half-installed, but I didn't check that). See [the man page of dpkg( for further "incomplete" states. – Ignitor Jan 17 '14 at 15:13
@Ignitor, good point. My answer was wrong. The package could even be removed, but not purged. So I think you have to examine the output to check, if the package is installed or not. – jarno Feb 6 '14 at 21:48
I edited the answer. Now it relies on output of dpkg-query. I don't know how portable this solution is; for example, may the text be displayed in another language in some system? – jarno Feb 6 '14 at 22:09

Example to use specific value as var in shell scripts (eg

INSTALLED=$(dpkg -l | grep ${PACKAGETOLOOKFOR} >/dev/null && echo "yes" || echo "no")

echo "${1} is installed ... ${INSTALLED}"

Make it executable and go start with: openssh-server

Or do whatever you want with in your scripts

share|improve this answer

Your Answer


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.