inaabi / Guides / Pin a package on Debian
Pin a package on Debian
Keep the installed version of one Debian package, or refuse a backport, and remove the pin file afterward.
Tested on Debian 12.15 and Debian 13.8, 2026-12-04.
Pins live in /etc/apt/preferences.d/. One file per decision. The file pin-bash, with no extension, worked. The man page is apt_preferences(5).
apt-cache policy is the check. The number on the version line is the priority apt will use. The test ran as root in a throwaway container on 2026-12-04. On a machine where you are not root, run the same commands with sudo.
Read the priority
These are the priorities the runs printed.
- 500: bookworm, bookworm-updates, bookworm-security, and the same suites for trixie. This is the candidate when the package is not installed.
- 100: the installed copy in
/var/lib/dpkg/status, and a backport before you ask for it. - 1001: a version pin on the installed bash. Above 1000, apt may downgrade to the pinned version.
- -1: the backport was not a candidate.
apt-get installexited 100.
A priority above 1000 can force a downgrade to that version. The bash pin used 1001 so a later version would not become the candidate. No newer bash was in the archive that day, so the candidate version did not change. The priority number did. That is what was proved.
Match the release you are on
apt-cache policy on Debian 12.15 labeled bookworm a=oldstable and bookworm-security a=oldstable-security. On Debian 13.8 it labeled trixie a=stable and trixie-security a=stable-security. A pin of release a=stable matches trixie, not bookworm. Pin the codename (n=bookworm or n=trixie), or the label you saw, not the word stable from an old example.
Keep the installed version
apt-cache policy bash
ver=$(dpkg-query -W -f '${Version}' bash)
cat > /etc/apt/preferences.d/pin-bash << EOF
Package: bash
Pin: version ${ver}
Pin-Priority: 1001
EOF
apt-cache policy bash
On Debian 12, bash 5.2.15-2+b13 went from priority 500 to 1001. The package file underneath stayed 500. Candidate and installed stayed 5.2.15-2+b13.
On Debian 13, bash 5.2.37-2+b10 went from 500 to 1001 the same way.
Refuse one backport
With tmux installed from backports (see Install one package from Debian backports):
cat > /etc/apt/preferences.d/never-tmux-backport << 'EOF'
Package: tmux
Pin: release n=bookworm-backports
Pin-Priority: -1
EOF
apt-cache policy tmux
apt-get install -s -t bookworm-backports tmux
On Debian 12 the installed backport showed priority -1 and Candidate: (none). The simulation exited 100: E: Package 'tmux' has no installation candidate. The package stayed installed. The pin blocks selection. It does not remove a package.
Bookworm's tmux 3.3a-3 stayed in the table at priority 500. It did not become the candidate, because moving from 3.5a to 3.3a is a downgrade and 500 does not downgrade.
On Debian 13 the same file with n=trixie-backports did the same to tmux 3.7c-1~bpo13+1. The candidate became (none). Trixie's 3.5a-3 stayed at priority 500. The simulation exited 100.
Prefer one backport
After the backport was already installed, this file raised that version's priority from 100 to 500:
cat > /etc/apt/preferences.d/prefer-tmux-backport << 'EOF'
Package: tmux
Pin: release n=bookworm-backports
Pin-Priority: 500
EOF
apt-cache policy tmux
The version line became 500. The bookworm-backports package file stayed 100. You do not need this file to install once. tmux/bookworm-backports does that. Use the file when a plain apt-get install tmux, with no suite suffix, should select the backport on a machine that does not have it yet. That before-install case was not the one recorded. The priority change after install was.
On Debian 13 the same file with n=trixie-backports raised the installed backport from 100 to 500.
Do not set Package: * to priority 500 for the whole backports suite unless you mean every later install to prefer backports. That was not tested.
Remove the pin
rm /etc/apt/preferences.d/pin-bash
apt-cache policy bash
Tested. On both releases bash returned to priority 500. The same rm undoes the tmux pins. Nothing else was edited.
apt-mark hold was not tested on this page.
Questions
Does priority 1001 hold the package if no newer version exists?
The priority changes, which is the mechanism that keeps a later version from becoming the candidate. On 2026-12-04 neither archive had a newer bash, so the candidate version stayed the one already installed. The test did not show apt refusing a newer bash, because none was published.
Does a pin of -1 uninstall the package?
No. tmux stayed installed. apt-get remove is what uninstalls it. The pin made apt-get install exit 100.