Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have to two repositories listed in my sources.list or sources.list.d is there a way to tell apt which is preferred?

My exact use case is if a package is found on the intranet repository and on the remote repository I want apt to always use the intranet one. Right now it seems to pick randomly between the two.

share|improve this question

You can do it by modifying your /etc/apt/preferences file; it's commonly referred to as "APT pinning". Here are some guides with details:

share|improve this answer
I read the manpage for apt_preferences. It has this line: "The APT preferences file does not affect the choice of instance, only the choice of version." It looks like APT preferences wont solve my specific use case. – deft_code Oct 26 '10 at 17:14
I think apt-pinning is Debian-only due to the fact that Ubuntu doesn't differn between stable, testing, unstable... maybe for Multimedia or so... bit normally the versions should be never... – wishi Oct 26 '10 at 22:08

It should be enough to list the intranet source first, in sources.list. According to the manual:

It is important to list sources in order of preference, with the most preferred source listed first. Typically this will result in sorting by speed from fastest to slowest (CD-ROM followed by hosts on a local network, followed by distant Internet hosts, for example).

From a cursory look at the source, sources.list is traversed first, then the files in sources.list.d in an order that you can't control.

share|improve this answer
That's a bummer. I wanted to distribute a package that dropped the intranet repo info in sources.list.d. But it looks like I'll have to edit the sources.list in the post-install, yuck. – deft_code Oct 26 '10 at 23:19

Assuming your package repository is at, creating a file called e.g. /etc/apt/preferences.d/company-pinning containing the following will do the trick:

Package: *
Pin: origin
Pin-Priority: 600

The default priority is 500, so this will prefer the latest version from the intranet server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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