I'm trying to master how APT pinning works under Debian, but I'm having a hard time grasping how it resolves priorities.

I have a source.list file that has the following entries in this exact order:

deb <repository> stretch main
deb <repository> testing main
deb <repository> unstable main

The following repository contains these packages per branch:

  • stretch contains the package dependency version 1.0;
  • testing contains the package dependency version 2.0;
  • unstable contains the packages program and dependency version 2.0;

The package program depends on dependency version 2.0.

I need to install the package program, but I want to install as few packages as possible from unstable, so I create the following preferences file to pin this branch:

Package: *
Pin: release a=unstable
Pin-Priority: -1

If I understand correctly how it works, it should install packages from unstable only when I explicitly tell APT to.

I also create a apt.conf file to ensure the stable branch is the default:

APT::Default-Release "stable";

After running the command apt-get update, the branches should have the following priorities:

stable: 990
testing: 500
unstable: -1

Now I want to install the package program, to do so, I run the following command:

apt-get install -t unstable program

So now my question is, from which branch will APT pull the package dependency version 2.0? As both testing and unstable have the same version of the package, which one will get picked?

If I understand correctly, APT with the -t unstable option, will set a 990 priority to the packages belonging to unstable, but from what I've experienced, it pulls it from testing.

So why does APT pulls packages from testing that has a priority of 500 while unstable as its set to 990? Also, what would be the optimal way to install as few packages as possible from unstable?

  • 1
    If the version is the same, then the file is the same also. Apt chooses the fastest or the 1st defined mirror, but the url of the downloaded file is the same. Check it yourself. Debian repositories doesn't store two identical files/version of a package due to disk space issues. Nov 13, 2018 at 22:50

1 Answer 1


This is explained in the apt_preferences manpage:

Several versions of a package may be available for installation when the sources.list(5) file contains references to more than one distribution (for example, stable and testing). APT assigns a priority to each version that is available. Subject to dependency constraints, apt-get selects the version with the highest priority for installation. The APT preferences override the priorities that APT assigns to package versions by default, thus giving the user control over which one is selected for installation.

Several instances of the same version of a package may be available when the sources.list(5) file contains references to more than one source. In this case apt-get downloads the instance listed earliest in the sources.list(5) file. The APT preferences do not affect the choice of instance, only the choice of version.

Priorities only determine which version (as specified by the version number) of a package is installed. Once that’s determined, the first available package repository is used to download it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .