Choose which repository or version apt should prefer and stop unwanted upgrades or downgrades. 16.11.2025 | reading time: 3 min Apt pinning gives the administrator precise control over which package versions the system prefers; use /etc/apt/preferences or files in /etc/apt/preferences.d to express that control and stop accidental upgrades or force safe downgrades. See it in action Start by inspecting the current situation, create a simple pin file, update, then re-check; example session: ```bash $ apt-cache policy nginx nginx: Installed: 1.18.0 Candidate: 1.20.0 Version table: 1.20.0 500 500 http://mirror/testing main amd64 Packages *** 1.18.0 100 100 /var/lib/dpkg/status # Create a pin to prefer the stable release for nginx $ sudo tee /etc/apt/preferences.d/pin-nginx > /dev/null <<'EOF' Package: nginx Pin: release a=stable Pin-Priority: 700 EOF $ sudo apt update $ apt-cache policy nginx nginx: Installed: 1.18.0 Candidate: 1.18.0 Version table: *** 1.18.0 700 700 http://mirror/stable main amd64 Packages 1.20.0 500 500 http://mirror/testing main amd64 Packages ``` How priorities guide apt Pin-Priority is the deciding number: values above 500 will make a version preferred over an installed release when newer, values above 1000 allow a downgrade to that version, values close to zero prevent installation, and 0 explicitly makes a version not installable; choose priorities deliberately to prefer an origin or to block it. Practical tips and traps Place small files in /etc/apt/preferences.d for clarity, run apt update after changing pins, inspect results with apt-cache policy, remember multiple pins combine and the highest effective priority wins, prefer pinning by "Package:" plus "Pin:" release or origin rather than exact version when maintaining many hosts, and favor apt-mark hold for a simple single-package hold as it is easier and less error-prone. Other helpers in the toolbox Use apt-cache policy to inspect priorities, apt-mark hold to freeze a package quickly, and aptitude when you need an interactive resolver to see how pinning affects upgrades and dependencies. Final line Mastering apt preferences prevents surprises during upgrades and lets the administrator mix repositories with confidence; if you like digging deeper into Linux internals, consider formalizing that skill with certifications like CompTIA Linux+ or LPIC-1 and intensive exam preparation at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. setup utilities troubleshooting