5

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.

2 Answers 2

6

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.

2
  • 1
    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 seems to be silent on this. Commented Jun 25, 2021 at 11:04
  • @NickBroon there’s no documentation that I’m aware of, but see ReadMainList() 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() requests a sorted list). Commented Jun 28, 2021 at 7:45
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 
3
  • 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. Commented Oct 28, 2018 at 17:26
  • Hi Ivan. Could you please help me with unix.stackexchange.com/questions/758929/…? Where to read about pin scores? Seems to me apt.conf.5 barely mentions them. Commented Oct 14, 2023 at 15:23
  • 1
    @Martian2020 man apt_preferences. Commented Oct 27, 2023 at 7:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.