4

If an application is available in multiple repositories added in either /etc/apt/sources.list or /etc/apt/sources.list.d/ or any other way, how does sudo apt install determine which repository to use?

Is there some searching order between the added repositories?

Thanks.

Tim
  • 101,790

2 Answers2

5

If multiple repositories provide the same version of a given package, the first one listed wins:

The files list one source per line (one-line style) or contain multiline stanzas defining one or more sources per stanza (deb822 style), with the most preferred source listed first (in case a single version is available from more than one source).

This also applies across files. /etc/apt/sources.list takes priority over any file in /etc/apt/sources.list.d; the latter are processed in lexical sort order.

Stephen Kitt
  • 434,908
2

There are also apt preferences to "pin" files from a specific server to a higher priority...

ivan@darkstar:/etc/apt$ cat preferences.d/official-package-repositories.pref 
Package: *
Pin: origin live.linuxmint.com
Pin-Priority: 750
ivanivan
  • 4,955
  • 1
    apt preferences only affect the version of a package which is chosen. If the same version is available from multiple repos, the order determines which repo is used, not the pin priorities. See man apt_preferences for details. – Stephen Kitt Oct 28 '18 at 17:26
  • Hi Ivan. Could you please help me with https://unix.stackexchange.com/questions/758929/apt-why-install-older-version-of-a-package-when-newer-is-available-via-sources? Where to read about pin scores? Seems to me apt.conf.5 barely mentions them. – Martian2020 Oct 14 '23 at 15:23
  • 1
    @Martian2020 man apt_preferences. – Stephen Kitt Oct 27 '23 at 07:51