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

Possible Duplicate:
How can I check if a package is installed (no superuser privileges)

I want a shell script method to test/report if a package is installed. I don't need details, only a yes/no.

I've come up with this method. Is there a more direct way?

test_installed=( `apt-cache policy domy-ce | grep Installed: ` )
[ ! "${test_installed[1]}" == "(none)" ] && is_installed=1
share|improve this question

marked as duplicate by Takkat, jokerdino, Jjed, Alvar, fossfreedom May 22 '12 at 18:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

This post should help you-… – saji89 May 22 '12 at 7:18
Thanks saji89. The apparent duplicate gives accurate results with Debian registered packages, the results are unreliable on Ubuntu PPA packages. With packages that are registered on the host but not installed, dpkg's returncode is zero [0]. – tahoar May 23 '12 at 13:04
up vote 16 down vote accepted

You could use the output of dpkg -s <packagename> or dpkg-query -l <packagename>

in your script for the purpose.



for P; do
    dpkg -s "$P" >/dev/null 2>&1 && {
        echo "$P is installed."
    } || {
        echo "$P is not installed."

Usage: package1 package2 .... packageN


share|improve this answer
If a package is installed then removed, then dpkg -s still exits with a 0 status! See – 200_success Oct 8 '15 at 22:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.