Linux – How does APT choose which packages to install

aptlinuxpackage-management

On my Debian Testing box, I have the following in /etc/apt/sources.list:

deb http://ftp.us.debian.org/debian/ testing main contrib non-free
deb-src http://ftp.us.debian.org/debian/ testing main contrib non-free

deb http://security.debian.org/ testing/updates main contrib non-free
deb-src http://security.debian.org/ testing/updates main contrib non-free

deb http://ftp.us.debian.org/debian/ testing-updates main contrib non-free
deb-src http://ftp.us.debian.org/debian/ testing-updates main contrib non-free

deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse proposed partner
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse

deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse proposed partner
deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse

Then suppose that I run sudo apt install libre-office. I see that it selects some required packages from ftp.us.debian.org and some from us.archive.ubuntu.com. How does APT decide which source to grab each package from?

Best Answer

The algorithm is described in much detail in the apt_preferences man page. In short, apt calculates a score for every version it knows about, based on command line options, configuration, and already installed packages. It then installs the version with the highest score.

You can tweak things by specifying explicit scores for explicit sources, as described in the same man page.

On a side note, mixing versions from Debian and Ubuntu like that is highly unlikely to work well; I would recommend against it.

Related Question