Skip to content

Instantly share code, notes, and snippets.

@toth-dev
Created March 20, 2017 21:19
Show Gist options
  • Save toth-dev/7c4ed8be2a21860ffe765395335bd07c to your computer and use it in GitHub Desktop.
Save toth-dev/7c4ed8be2a21860ffe765395335bd07c to your computer and use it in GitHub Desktop.
Apt pinning quick ref

Apt pinning quick ref ⭐

Add repository to /etc/apt/sources.list

Ubuntu Debian
deb http://archive.ubuntu.com/ubuntu zesty main universe deb http://ftp.us.debian.org/debian unstable main non-free contrib

Set priorities

Set default release (optional)

This prevents accidental upgrades by setting the priority of packages from the target release to 990 and to 500 for all other packages.

In /etc/apt/apt.conf or /etc/apt/apt.conf.d/<file>:

Ubuntu Debian
APT::Default-Release "yakkety"; APT::Default-Release "stable";

Set priorities for individual packages

You have two options here: you can either set the priorities in the preferences file(s) or overwrite them on command line.

In /etc/apt/preferences or /etc/apt/preferences.d/<file>:

Package: vim*
Pin: release n=zesty
Pin-Priority: 1000

The release can be specified with a distribution codename (n=zesty or n=stretch) or archive name (a=testing).

Overwriting priorities:

# apt install vim/zesty
# apt -t zesty install vim

The first will not attempt to upgrade any packages on your system, so if specific dependencies are not met, the install will fail. The second method will attempt to install/upgrade any dependencies.


A word of caution

From apt_preferences(5):

APT will not question the preferences, so wrong settings can lead to uninstallable packages or wrong decisions while upgrading packages. Even more problems will arise if multiple distribution releases are mixed without a good understanding of the following paragraphs. Packages included in a specific release aren't tested in (and therefore don't always work as expected in) older or newer releases, or together with other packages from different releases. You have been warned.


Sources/more info: apt.conf(5) apt_preferences(5)

Ubuntu Community Wiki

Debian Wiki

Apt-Pinning for Beginners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment