How does APT choose the specific package to install in order to provide a virtual package needed as a dependency?

How does APT choose the specific package to install in this case?

APT doesn't select a package. It tells:

You should explicitly select one to install.

If you try to manually select a package, it wouldn't be installed.

In the case of base-files depending on awk it is irrelevant. First, it actually PreDepends on awk, forcing dpkg to install awk before starting to install base-files; second, mawk have priority required which are installed at system installation, and apt nags you if you try to remove it. So, just don't do it.

Now, according to sources, apt tries first of satisfying the dependency before trying with virtual packages (i.e., if depends are firefox | www-browser, checks if any of the packages are installed, then try to install firefox if neither is). If the non-virtual package isn't available, it seems to just iterate over all packages which provides the virtual package, if no other dependencies are broken. Other comments evidence of this behavior are this which leads to GrpIterator::FindPreferredPkg function.


It is not specified in Debian Packaging Policy which specific real package is installed if there are alternative packages providing a virtual package.

If this is crucial for some package to depend on some specific real package, then it should be specified in Depends.

But if there are conflicts with one real package and another can be install providing the same virtual package, then a non-conflicting package will be installed.

You can check which awk is used by running

readlink /etc/alternatives/awk