Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, awk is a virtual package provided by original-awk, mawk and gawk.

Trying to install it directly yields:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package awk is a virtual package provided by:
  original-awk:i386 2012-12-20-4
  mawk:i386 1.3.3-17ubuntu2
  gawk:i386 1:4.1.1+dfsg-1
  original-awk 2012-12-20-4
  mawk 1.3.3-17ubuntu2
  gawk 1:4.1.1+dfsg-1
You should explicitly select one to install.

E: Package 'awk' has no installation candidate

However many virtual packages are needed as dependencies by the packages installed by default, for example awk itself is needed by base-files, which checking the APT logs is installed along with a bunch of other packages through apt-get --yes; somehow APT ends up picking one of the three automatically (I'm pretty sure that's mawk, but that's not the point of the question).

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

share|improve this question
1  
Keep in mind that "virtual packages" are provided by something else - you have to check what is actually awk. Check what package the awk manpage came from - it may specify which one is actually installed. – Thomas W. Feb 25 at 14:30
1  
@ThomasW. Also readlink -f $(which awk) is a good hint (e.g. on my system /usr/bin/gawk with gawk installed and /usr/bin/mawk with gawk uninstalled). Problem is, this question actually arises from the fact that due to multiple gawk reinstallations I can't check this that way no more, because the link (and the man page for that matter) just points to the latest manually installed / the only one actually installed. So I was trying to grasp the "original" one the other way around, but at the end I ended up being more interested in knowing how the choice is made. – kos Feb 25 at 14:44
    
I have both installed gawk and mawk. They do not conflict. – Pilot6 Feb 25 at 14:47
    
@Braiam Why do you think the question is not about dependencies? It's actually specific to dependencies, though restricted to virtual packages. Not sure why you removed "package-management" but I won't disagree too much, it's so broad (and lacks a wiki) in a way that leaves it open to any interpretation. Per how I read it it looked so broad that I thought "package managment (in this case done by APT)" would have fit, but I might well have overread it (if you disagree and don't mind, please let me know how it's supposed to be read instead). – kos Feb 25 at 18:08
up vote 3 down vote accepted

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.

share|improve this answer

It is not specified in Depian 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
share|improve this answer
    
Yep, that's why I'm asking. Since mawk and gawk don't conflict, why installing mawk and not gawk? Are you suggesting that some other package in the apt-get --yes command I mentioned explicitly required mawk? – kos Feb 25 at 14:51
    
It either this case, or apt has chosen the first it found. – Pilot6 Feb 25 at 14:55
    
+1 for the "another package needing it" hint, that's very likely. I'll test that and the "first it found" hint later or tomorrow (I can't remove all AWKs without breaking the system, so I'll need to find a suitable package etc), I'll let you know what happens. – kos Feb 25 at 16:14
    
@kos the base system isn't installed in the normal fashion. Installing stuff in the normal way, nothing chooses mawk, you get the "pick one" message that you quoted in your question, and --yes doesn't have an effect on it. – hobbs Feb 25 at 19:53
    
(easily tested by dpkg --remove --force-all mawk gawk ; apt-get --yes install awk. It doesn't install anything.) And no, it doesn't break the system badly enough to prevent apt-get install mawk from working.) – hobbs Feb 25 at 19:56

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.