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?


2 Answers 2


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.

  • 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.
    – NickBroon
    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). Jun 28, 2021 at 7:45

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
  • 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. Oct 28, 2018 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.