18

Some packages, have a Provides: header. For example, the package postfix on Debian Wheezy has Provides: mail-transport-agent.

The package mail-transport-agent which doesn't exist physically is considered as a "virtual" package.

How can I know, on a Debian based system, if a given virtual package is "installed" (or "provided")? Can I list every "provided" virtual package?

Hint: to list every existing virtual package, installed or not, do: aptitude search "~v"

Totor
  • 19,302
  • 17
  • 75
  • 102

4 Answers4

17

To list packages providing mail-transport-agent:

$ aptitude search '~Pmail-transport-agent'
p   citadel-mta                     - complete and feature-rich groupware server
p   courier-mta                     - Courier mail server - ESMTP daemon        
p   dma                             - lightweight mail transport agent          
p   esmtp-run                       - user configurable relay-only MTA - the reg
p   exim4-daemon-heavy              - Exim MTA (v4) daemon with extended feature
p   exim4-daemon-light              - lightweight Exim MTA (v4) daemon          
p   masqmail                        - mail transport agent for intermittently co
p   msmtp-mta                       - light SMTP client with support for server 
p   nullmailer                      - simple relay-only mail transport agent    
i   postfix                         - High-performance mail transport agent     
p   sendmail-bin                    - powerful, efficient, and scalable Mail Tra
p   ssmtp                           - extremely simple MTA to get mail off the s
p   xmail                           - advanced, fast and reliable ESMTP/POP3 mai

Make that aptitude search '~Pmail-transport-agent ~i' to only list installed packages (if any).

To list all virtual packages provided by currently installed packages:

aptitude search '~Rprovides:~i ~v'

See the aptitude manual for an explanation of the search patterns.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Accepting this answer because is uses standard `aptitude`. I like the explaination of @umläute though. – Totor Dec 31 '13 at 14:41
  • 1
    On Debian Jessie, I just tried `aptitude search '~Pmysql-server ~i'` which gives `mariadb-server-10.0` and `mariadb-server-core-10.0`, but when I do `aptitude search '~Rprovides:~i ~v'`, I do not see `mysql-server` in the list... However, I do see `virtual-mysql-client`, `virtual-mysql-client-core`, `virtual-mysql-server` and `virtual-mysql-client-core` in the list. – Totor Jun 09 '16 at 15:14
  • 1
    @figtrap It's faster, sure, [but it doesn't work](https://unix.stackexchange.com/questions/96309/how-can-i-know-if-a-virtual-package-is-installed-on-a-debian-system/96399?noredirect=1#comment146232_96454). – Gilles 'SO- stop being evil' Mar 10 '18 at 00:37
  • That is so useful, do you know how to do this on other package managers? (BTW your link is now 404) – user1133275 Apr 15 '22 at 17:10
  • @user1133275 I don't know how to do it with `apt-cache` or `apt`. – Gilles 'SO- stop being evil' Apr 15 '22 at 18:55
12

the problem here is that there is a subtle difference between virtual packages and packages provided by other packages.

the difference is, that a package may provide a real package as well, not only a virtual package.

anyhow, the following will search for all packages that provide a package and will print both the package name and the packages it provides:

grep-available -sPackage  -sProvides -FProvides -e '^.'

to find whether any package is installed on your system that provides a given one (e.g. mail-transport-agent), use

grep-status -sPackage -sProvides -FProvides "mail-transport-agent"
umläute
  • 6,300
  • 1
  • 24
  • 48
  • 3
    Note: the commands `grep-available` and `grep-status` are available once you installed the `dctrl-tools` package. – Totor Oct 17 '13 at 14:17
  • This does not really work, eg: `grep-available -sPackage -FProvides 'mail-transport-agent' ` fails to show anything. – user1133275 Apr 15 '22 at 17:07
2

You can detect the presence of a given virtual package by using apt-cache showpkg <virtual> to display a list of candidate packages, and then dpkg -l <canddate> <candidate> ... to display the installation status of the candidates.

For example:

$ apt-cache showpkg awk
$ dpkg -l original-awk mawk gawk

Here is a full printout:

$ apt-cache showpkg awk
Package: awk
Versions: 

Reverse Depends: 
  base-files,awk
  base-files,awk
Dependencies: 
Provides: 
Reverse Provides: 
mawk:i386 1.3.3-17ubuntu2
gawk:i386 1:4.0.1+dfsg-2.1ubuntu2
original-awk 2012-12-20-1
mawk 1.3.3-17ubuntu2
gawk 1:4.0.1+dfsg-2.1ubuntu2

$ dpkg -l original-awk mawk gawk
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  gawk           1:4.0.1+dfsg amd64        GNU awk, a pattern scanning and p
ii  mawk           1.3.3-17ubun amd64        a pattern scanning and text proce
dpkg-query: no packages found matching original-awk

I believe dpkg and apt-cache are lower level tools than aptitude, grep-available and grep-status. Using lower level tools may or may not be a benefit, depending upon your particular requirements.

mpb
  • 1,501
  • 1
  • 15
  • 23
  • That did not work for me in the case a virtual package has replaced a real package. `apt-cache search package` listed the real and virtual package provider. – gerardw Oct 27 '20 at 14:16
-1

You can get all of the virtual packages from the AUTHORITATIVE LIST OF VIRTUAL PACKAGE NAMES. As for determining if a virtual package is installed I use dpkg -l and the fact that it has an exit code of 0 if the package is installed and an exit code of 1 if it is not installed.

dpkg -l mail-transport-agent &> /dev/null; echo $?
StrongBad
  • 5,151
  • 9
  • 47
  • 73
  • No, this doesn't work. `dpkg -l mail-transport-agent` can return 0 even if there is no package providing it that is currently installed. I think it's based on presence in `/var/dpkg/lib/available` but I'm not sure. I did check that `dpkg -l foo` returns 1 for a package that I've never installed but 0 for a package that I just purged. – Gilles 'SO- stop being evil' Oct 17 '13 at 10:17
  • Your Link id 404. – user1133275 Apr 15 '22 at 16:56