2

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
  • 98,580
  • 191
  • 570
  • 977

2 Answers2

4

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
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Do you have any links to man-pages, docs or code that confirms that `sources.list.d` are processed in lexical order, and that `sources.list` takes priority over all of those? The [source.list man-page](https://manpages.debian.org/sources.list) seems to be silent on this. – NickBroon Jun 25 '21 at 11:04
  • @NickBroon there’s no documentation that I’m aware of, but see [`ReadMainList()`](https://salsa.debian.org/apt-team/apt/-/blob/2a4c2d051db91638d9c475ebbf636694f18d12cc/apt-pkg/sourcelist.cc#L307) in the APT source code; it reads the main `sources.list` file first, then any files in `sources.list.d`, sorted in lexical order (the `true` flag in [the call to `GetListOfFilesInDir()`](https://salsa.debian.org/apt-team/apt/-/blob/2a4c2d051db91638d9c475ebbf636694f18d12cc/apt-pkg/sourcelist.cc#L502) requests a sorted list). – Stephen Kitt Jun 28 '21 at 07:45
1

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,870
  • 1
  • 9
  • 20
  • `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`](https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html) for details. – Stephen Kitt Oct 28 '18 at 17:26