Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

5 Answers 5

up vote 26 down vote accepted
apt-cache policy <package name>
share|improve this answer
4  
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

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(manpages.ubuntu.com/manpages/oneiric/man1/dpkg.1.html) for further "incomplete" states. –  Ignitor Jan 17 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 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 at 22:09

One more variant, using aptitude this time:

aptitude show <package>

Tab completion works here as well.

share|improve this answer

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
1  
dpkg -l "*mysql*" also works and does not hide the explanatory lines in the output. –  Philipp Wendler Aug 9 '12 at 15:37

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 –  belacq Feb 9 '11 at 8:35

Your Answer

 
discard

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.