This question explains how to find out if a given Debian package has been installed, but it does not take into account "synonyms" when installing via apt-get
.
For instance, if I try apt-get install libncurses-dev
, apt-get replies:
Note, selecting 'libncurses5-dev' instead of 'libncurses-dev'
And then it installs that package (libncurses5-dev
), which is fine by me.
But what if I want to make a script to detect if the package has already been installed?
dpkg -s libncurses-dev
replies that the package is not installed, which is indeed correct, since it's libncurses5-dev
that was installed. But I'd like my script to detect that, in this case, it no longer needs to install libncurses-dev
.
I could not find an option in apt-get
to check if the given package or one of its providers has already been installed, such that my script would work when checking for libncurses-dev
as well as for libncurses5-dev
.
Best Answer
If you want to write a script to check to see if package
libncurses-dev
or its alias has been installed, consider the following program flow:dpkg
using the exact name,libncurses-dev
in this case.If the above does not evaluate to true, then search
apt
for the package you are looking for using the non-aliased name:It appears that
apt-cache search
will return the 'alias' if the package has one.Check
dpkg
again with the alias name of the package, in this case it would belibncurses5-dev
. Ifdpkg
does not find the package by an alias (actually a superseded package) then it must not be installed.