Version pinning and upgrades
Quick answer
A reliable upgrade begins with inventory, candidate selection, a simulated transaction and a recovery plan. A hold and an APT priority pin solve different problems.
Prepare the practice environment
Use an ordinary user in a disposable VM of the distribution named in the example. For Debian examples use python3 lab-fixtures/packages/setup.py from the extracted package root, enter the printed directory and check pwd; alternatively create a private directory with mktemp -d. Use a fresh directory per example, export LC_ALL=C and Bash with set -o pipefail. Do not use sudo. Keep -s and --no-download on every APT simulation. Skip missing tools; do not install them merely to run an example. On Alpine the simple query also works in a compatible sh. Outputs vary by installed versions and repository state. Stop on unexpected failure.
How it works
apt-mark hold NAME changes package selection so automatic changes are prevented in ordinary workflows; showhold reads holds. APT preferences can assign priorities to versions or releases, affecting candidate selection. Do not freeze security updates indefinitely. apt-get -s upgrade previews an upgrade using available cached indexes; simulation does not reserve the state or prove service compatibility. Save package inventory, application data and configuration, and test restoration before changes. A downgrade is not a universal rollback; data migrations can be irreversible. In a VM use a verified snapshot and review the plan including removals and held packages.
Version strings are not ordinary decimal numbers. In the example, Debian version ordering treats 1.10 as newer than 1.2; use the package manager comparison rather than a numeric or lexical sort. An empty successful showhold result means no holds were reported, but a failed query can also leave an empty redirected file. Check its status before drawing a conclusion. An upgrade summary confirms that a plan was produced, not that every candidate is safe. Review held packages, exact versions and the recovery procedure separately.
Try the examples
if dpkg --compare-versions 1.10 gt 1.2; then printf '1.10 is newer\n'; fiDebian version ordering is not simple string sorting. This is a synthetic comparison, not a package change.
Expected stdout:
1.10 is newerRead holds.txt; it may be empty. No hold was added or removed.
Expected stdout:
hold query completeapt-get -s --no-download upgrade > upgrade-plan.txtgrep -q 'upgraded,' upgrade-plan.txt && printf 'upgrade summary found\n'The summary is a text check in the tested C locale, not a machine API. Read the whole plan; no packages were fetched or changed.
Expected stdout:
upgrade summary foundCommon mistakes
Do not assume a pin is a backup or that a successful simulation guarantees a successful upgrade. Do not use automatic confirmation before reviewing removals.
Practice
Save the package inventory of a disposable Debian VM, inspect holds and simulate an upgrade. Write a three-step recovery plan that includes application data and a tested snapshot; do not apply the transaction.
Related references
Study: apt-mark, apt-get. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Version pinning and upgrades — Knowledge Check
Apply package-management concepts to the stated distribution and query-only lab.
What does an APT pin influence?
Which operation only inspects held packages?
Why is a simulation not a guarantee?
What should a rollback plan include?