How to know whether a particular package is installed on ubuntu? [duplicate]
I installed a JDK package on my Ubuntu 14.04 a few months ago, but I don't know how to check which version it is.
So how to do I find whether a package is installed on Ubuntu and which version of it is installed?
Solution 1:
TL;DR: For a simple command (no | grep
) with compact output, you can use
-
apt list package
, which is usually what you want (compare toapt-cache policy package
), or -
dpkg-query -W package
as a less cluttered version ofdpkg -l
.package
The apt
command (for apt list package
) is available in Ubuntu 14.04 and later.
apt list
tells you if your package is installed.
apt list package
shows the version of a package that is or would be installed, along with the names of the repository components that provide it and the version. When the package is installed, [installed]
appears prominently at the end of the line.
ek@Io:~$ apt list firefox
Listing... Done
firefox/xenial-updates,xenial-security,now 51.0.1+build2-0ubuntu0.16.04.1 amd64 [installed]
N: There is 1 additional version. Please use the '-a' switch to see it
In addition to [installed]
at the end, now
in the list of repository components indicates that the package is currently installed. This is what apt list
's output looks like for a package that isn't installed:
ek@Io:~$ apt list dolphin
Listing... Done
dolphin/xenial 4:15.12.3-0ubuntu1 amd64
Sometimes you'll see [installed,automatic]
, which means the package was installed as a dependency of some other package. Since it was automatically rather than manually installed, it can be removed after all the packages that depend on it are removed (which is what the apt autoremove
command does).
ek@Io:~$ apt list zeitgeist-core
Listing... Done
zeitgeist-core/xenial,now 0.9.16-0ubuntu4 amd64 [installed,automatic]
You can use apt list --installed
to show only installed packages.
One advantage of seeing a listing even when the package isn't installed is that you know there is a package of the name you specified. Otherwise, if you spell it wrong by accident, you might think the package you meant isn't installed.
ek@Io:~$ apt list firefoz
Listing... Done
But if you really do prefer that nothing appear if you don't have a package, use apt list --installed package
:
ek@Io:~$ apt list --installed firefox dolphin
Listing... Done
firefox/xenial-updates,xenial-security,now 51.0.1+build2-0ubuntu0.16.04.1 amd64 [installed]
N: There is 1 additional version. Please use the '-a' switch to see it
Globbing helps you list packages whose names you don't know or want to type.
As you've just seen, you may pass multiple package names to apt list
. The other thing you can do is pass it a glob, where a *
represents zero or more characters and ?
represents one character. There are a few things to keep in mind:
-
Your shell also expands globs into filenames, but that is not what you want to happen here, so you should always quote them (in
'
'
or"
"
, or with\
) when you pass them toapt list
. - Although both globs and regular expressions both support character classes (e.g.,
[csz]sh
matchescsh
,ssh
zsh
), they are not the same and*
and?
mean different things in a glob than in a regular expression. This is important because some other commands used to get information about packages, such asapt-cache policy package
, use regular expressions rather than globs. You should check if a command uses globs or regular expressions before relying on either feature. -
When you are actually adding and removing packages, you must not confuse globs with regular expressions.
apt list 'wine*'
lists all the packages whose names start withwine
, butapt remove 'wine*'
removes all the packages withwin
(even without thee
) anywhere in their name!
Suppose, for example, that I know the package I'm interested in has soap
in its name somewhere and ends in cil
, but that's all I remember:
ek@Io:~$ apt list '*soap*cil'
Listing... Done
libmono-system-runtime-serialization-formatters-soap4.0-cil/xenial,xenial,now 4.2.1.102+dfsg2-7ubuntu4 all [installed,automatic]
Globbing is also handy when you do know the full name of the package you're interested in, but don't want to type it. Or when you're interested in multiple packages that match the glob:
ek@Io:~$ apt list 'firefox-locale-*'
Listing... Done
firefox-locale-af/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-an/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ar/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-as/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ast/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-az/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-be/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-bg/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-bn/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-br/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-bs/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ca/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-cak/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-cs/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-csb/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-cy/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-da/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-de/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-el/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-en/xenial-updates,xenial-security,now 51.0.1+build2-0ubuntu0.16.04.1 amd64 [installed]
firefox-locale-eo/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-es/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-et/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-eu/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-fa/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-fi/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-fr/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-fy/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ga/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-gd/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-gl/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-gn/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-gu/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-he/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-hi/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-hr/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-hsb/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-hu/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-hy/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-id/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-is/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-it/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ja/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ka/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-kab/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-kk/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-km/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-kn/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ko/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ku/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-lg/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-lt/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-lv/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-mai/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-mk/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ml/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-mn/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-mr/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ms/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-nb/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-nl/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-nn/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-nso/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-oc/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-or/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-pa/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-pl/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-pt/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ro/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ru/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-si/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sk/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sl/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sq/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sr/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sv/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-sw/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-ta/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-te/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-th/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-tr/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-uk/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-uz/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-vi/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-xh/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-zh-hans/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-zh-hant/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
firefox-locale-zu/xenial-updates,xenial-security 51.0.1+build2-0ubuntu0.16.04.1 amd64
That's a lot of packages. (Though not as many as if I had run apt list '*'
, which lists all available packages!) Fortunately globs work with --installed
too:
ek@Io:~$ apt list --installed 'firefox-locale-*'
Listing... Done
firefox-locale-en/xenial-updates,xenial-security,now 51.0.1+build2-0ubuntu0.16.04.1 amd64 [installed]
N: There is 1 additional version. Please use the '-a' switch to see it
apt list
vs. dpkg-query -W
Another command you can use is dpkg-query -W package
. This is similar to dpkg -l
, but its output is more streamlined and readable because only the package name and installed version (if any) are printed.
dpkg-query -W
lists all packages dpkg
knows about that match the name or glob pattern you give it. This includes packages that are installed and also packages that aren't installed but that are referred to by another package. You can tell what packages are actually installed because the installed version number/string is printed to the right of the name. For example, on my 16.04 system:
ek@Io:~$ dpkg-query -W wine-\*
wine-amd64
wine-gecko
wine-gecko2.21:amd64 2.21-0ubuntu1
wine-gecko2.21:i386 2.21-0ubuntu1
wine-i386
wine-mono
wine-mono0.0.8 0.0.8-0ubuntu1
Thus, of listed packages, wine-gecko2.21:amd64
and wine-gecko2.21:i386
(i.e., wine-gecko2.21
for both the amd64
and i386
architectures) and wine-mono0.0.8
are the ones that I currently have installed.
dpkg-query -W
and apt list
will both always know about installed packages, whether or not they are provided by any currently configured software source and whether or not they are referred to by other packages. However:
-
apt list
also knows about packages available from any currently configured software source, but does not knows about unavailable packages referred to by other packages. -
dpkg-query -W
(likedpkg -l
) does not directly reflect what packages are actually available, but does know about packages referred to by any package that is installed.
On the same machine:
ek@Io:~$ apt list wine-\*
Listing... Done
wine-development/xenial,xenial 1.9.6-1 all
wine-gecko2.21/xenial,now 2.21-0ubuntu1 amd64 [installed,automatic]
wine-mono0.0.8/xenial,xenial,now 0.0.8-0ubuntu1 all [installed,automatic]
As with dpkg -l
, when you run dpkg-query -W
with the name of a package you don't have (e.g., I don't have chocolate-doom
installed), the output is the same as when you run it with the name of a package that doesn't exist at all (for example, due to misspelling, like firefoz
):
ek@Io:~$ dpkg-query -W chocolate-doom firefoz
dpkg-query: no packages found matching chocolate-doom
dpkg-query: no packages found matching firefoz
In contrast, apt list
shows explicitly that only chocolate-doom
exists (but isn't installed):
ek@Io:~$ apt list chocolate-doom firefoz
Listing... Done
chocolate-doom/xenial 2.2.1-2.1 amd64
Solution 2:
In a terminal, run dpkg -l | grep <name or pattern>
. For example,
dpkg -l | grep firefox
ii firefox 51.0.1+build2-0ubuntu0.14.04.2 amd64
The ii
thing means it is installed. Obviously, if there is no output, the package is not installed.
Solution 3:
If you know package name, use apt-cache
policy:
$ apt-cache policy firefox | grep 'Installed:'
Installed: 51.0.1+build2-0ubuntu0.16.04.1
$ apt-cache policy golang | grep 'Installed:'
Installed: (none)
If you don't , use dpkg --get-selections | grep 'jdk'
$ dpkg --get-selections | grep 'jdk'
jdk1.8.0-111 deinstall
openjdk-7-jre-headless:amd64 deinstall
openjdk-8-jdk:amd64 install
openjdk-8-jdk-headless:amd64 install
openjdk-8-jre:amd64 install
openjdk-8-jre-headless:amd64 install
openjdk-9-jre-headless:amd64 deinstall
Solution 4:
Use dpkg command, which is package manager for Debian.
>dpkg -s /package name/
Use file /var/lib/dpkg/available to find out all package names available to you.
Or you can use following command (It lists all packages in /var/lib/dpkg/status):
>dpkg-query -l
You can also try to match package name using wild cards:
>dpkg-query -l 'libc6*'