Set higher preference/priority to a apt repository over another

Written by - 0 comments

Published on January 28th 2014 - Listed in Linux

In some particular scenarios, it is necessary to add several repositories on a Debian system. In this scenario I'm talking about Proxmox, a virtualization solution based on Debian Wheezy. 

By default Proxmox installs its Enterprise repository in /etc/apt/sources.list.d/pve-enterprise.list:

cat /etc/apt/sources.list.d/pve-enterprise.list
deb wheezy pve-enterprise

However this repo is only accessible with a valid subscription. As an alternative, the community repository can be added and used:

cat /etc/apt/sources.list.d/pve--no-subscription.list
deb wheezy pve-no-subscription

Some packages in the Proxmox repository are far newer than on the official Debian repository.
As an example, the glusterfs packages have a big version difference:

  • glusterfs-server (3.2.7-3+deb7u1) in the official Debian repository
  • glusterfs-server (3.4.1-1) in the Proxmox repository

This causes apt-get install to fail because it doesn't know which version to install.
In such a situation it makes sense to set a preference on a repository over the others.

Such a preference can be set by setting different higher pin-priorities on the repositories in a preferences config file:

cat /etc/apt/preferences.d/proxmox
Package: *
Pin: origin
Pin-Priority: 900

Package: *
Pin: origin
Pin-Priority: 850

Package: *
Pin: origin
Pin-Priority: 800

Package: *
Pin: origin
Pin-Priority: 700

The content of the file is pretty much self-explaining. Each repository URL has its own Pin-Priority.
The higher the number, the higher is the priority.

It would also be possible to set the higher priority only for certain packages. In my example I have set the priorities for all packages (*).

Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.