Running apt upgrade updates every installed package on your system. That is fine for routine maintenance, but in production you often need to upgrade just one package: apply a security patch to OpenSSL without touching your database server, or update Nginx while keeping PHP pinned to a tested version. Targeted upgrades reduce risk and keep your change window small.
This guide covers every apt technique for managing individual package versions on Ubuntu and Debian systems: checking installed and available versions, upgrading a single package, pinning versions, downgrading, and simulating changes before applying them. The version, upgrade, downgrade and dry-run output below was recaptured in November 2026 on Ubuntu 24.04 (apt 2.8.4), with Ubuntu 22.04 (apt 2.4.15) and Debian 12 (apt 2.6.2) for comparison.
Prerequisites
- A server or workstation running Ubuntu 24.04 / 22.04 or Debian 13 / 12
- Root or sudo access
- Package index updated: run
sudo apt updatebefore starting
The examples use Nginx because Ubuntu ships it as two packages that must move together, which is exactly where single-package upgrades and downgrades trip people up. Ubuntu 22.04 splits it further into nginx-core and six libnginx-mod packages that all move in lockstep, so check the full set with apt list --installed | grep nginx before you pin or hold anything. If you use GCP, the stock ubuntu-2404-lts-amd64, ubuntu-2204-lts and debian-12 image families are where these captures came from. We first installed the release-pocket build with sudo apt install nginx=1.24.0-2ubuntu7 nginx-common=1.24.0-2ubuntu7 so there was an upgrade to work with. The structure of the output will match yours, while build numbers and pending-update counts drift as new updates land.
Step 1: Check the Installed Version of a Package
Before upgrading, confirm which version is currently installed. The apt list command shows installed packages filtered by name.
apt list --installed 2>/dev/null | grep nginx
On the Ubuntu 24.04 VM we tested on, nginx was still on the build from the release pocket, so both lines carry an upgrade hint.
nginx-common/noble,now 1.24.0-2ubuntu7 all [installed,upgradable to: 1.24.0-2ubuntu7.21]
nginx/noble,now 1.24.0-2ubuntu7 amd64 [installed,upgradable to: 1.24.0-2ubuntu7.21]
Notice that the grep caught two packages, not one. The nginx binary package depends on nginx-common at exactly the same version, so the two always upgrade and downgrade as a pair. Keep that in mind, because it’ll change what “upgrade one package” means in Steps 3 and 6.
For more detail including the description, use dpkg -l instead:
dpkg -l nginx
This displays the package status, installed version, and a short description:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-===============-============-==========================================
ii nginx 1.24.0-2ubuntu7 amd64 small, powerful, scalable web/proxy server
The ii flags at the start of the line confirm the package is installed cleanly, which is worth checking before any upgrade.
Step 2: Check the Available Version in Repositories
The apt policy command shows the installed version alongside all available versions from configured repositories. This tells you whether an upgrade is available and which repository provides it.
apt policy nginx
The output lists the installed version, the candidate (version apt would install), and all available versions with their repository sources:
nginx:
Installed: 1.24.0-2ubuntu7
Candidate: 1.24.0-2ubuntu7.21
Version table:
1.24.0-2ubuntu7.21 500
500 http://us-central1.gce.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages
*** 1.24.0-2ubuntu7 500
500 http://us-central1.gce.archive.ubuntu.com/ubuntu noble/main amd64 Packages
100 /var/lib/dpkg/status
If Installed and Candidate show different versions, an upgrade is available. The three stars mark the version on disk, and the 500 priorities say both builds come from regular archive pockets, so apt picks the higher version by default. Only two nginx builds are indexed here, the original release and the newest update, because Ubuntu’s Packages files carry just the latest version per pocket. That matters later, since you can’t apt install a version that isn’t listed in this table.

Keep an eye on the Candidate line. While it differs from Installed, the targeted upgrade in the next step has something to do.
Step 3: Upgrade a Single Package with apt
Use the --only-upgrade flag with apt install to upgrade a single package without installing it if it is not already present. This is the safest approach for targeted upgrades.
sudo apt install --only-upgrade nginx
apt resolves dependencies and shows exactly what will change before asking for confirmation:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
nginx-common
Suggested packages:
fcgiwrap nginx-doc ssl-cert
The following packages will be upgraded:
nginx nginx-common
2 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Need to get 571 kB of archives.
After this operation, 7168 B of additional disk space will be used.
Do you want to continue? [Y/n]
The line to read is “2 upgraded, 0 newly installed, 0 to remove and 12 not upgraded”. You asked for nginx, apt added nginx-common because of the exact-version dependency, and the 12 other pending updates on the box stayed where they were. The “additional packages will be installed” heading looks alarming, but nginx-common is already installed and only moves to the new build. If the package is not installed at all, --only-upgrade skips it and changes nothing, which makes it safe to run across a fleet where only some hosts have the package. The terminal below adds --assume-no, which prints the same plan and answers no, so nothing changed on the test box.

To upgrade multiple specific packages in one command, list them separated by spaces:
sudo apt install --only-upgrade nginx openssl curl
After the upgrade completes, verify the new version is active:
apt policy nginx
The Installed and Candidate lines now agree, and the stars have moved to the update build.
nginx:
Installed: 1.24.0-2ubuntu7.21
Candidate: 1.24.0-2ubuntu7.21
Version table:
*** 1.24.0-2ubuntu7.21 500
500 http://us-central1.gce.archive.ubuntu.com/ubuntu noble-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu noble-security/main amd64 Packages
100 /var/lib/dpkg/status
1.24.0-2ubuntu7 500
500 http://us-central1.gce.archive.ubuntu.com/ubuntu noble/main amd64 Packages
If the Installed line still shows the old version after the upgrade finishes, run apt update and check the policy again.
Step 4: Upgrade a Package to a Specific Version
Sometimes you need a specific version rather than the latest available. This is common when testing a known-good release or matching a version across multiple servers. Start by listing every version apt can see, so you have the exact string to pin:
apt list -a nginx 2>/dev/null
We ran this on Ubuntu 24.04 with apt 2.8.4 before the upgrade in Step 3, and the list reads as follows.
Listing... Done
nginx/noble-updates,noble-security 1.24.0-2ubuntu7.21 amd64 [upgradable from: 1.24.0-2ubuntu7]
nginx/noble,now 1.24.0-2ubuntu7 amd64 [installed,upgradable to: 1.24.0-2ubuntu7.21]
The bracketed hints are not new. Ubuntu 22.04 ships apt 2.4.15 and prints the same [upgradable from: ...] and [installed,upgradable to: ...] markers for its own nginx builds:
Listing... Done
nginx/jammy-updates,jammy-security 1.18.0-6ubuntu14.24 amd64 [upgradable from: 1.18.0-6ubuntu14]
nginx/jammy,now 1.18.0-6ubuntu14 amd64 [installed,upgradable to: 1.18.0-6ubuntu14.24]
Debian 12 with apt 2.6.2 does the same. Its suite names now read oldstable, because Debian 13 is the current stable release, so scripts that grep for “stable” will match Debian 12 hosts too:
Listing... Done
nginx/oldstable-security 1.22.1-9+deb12u11 amd64 [upgradable from: 1.22.1-9+deb12u9]
nginx/oldstable,now 1.22.1-9+deb12u9 amd64 [installed,upgradable to: 1.22.1-9+deb12u11]
With the string in hand, pin it with an equals sign:
sudo apt install nginx=1.24.0-2ubuntu7.21
Copy the full version string exactly as shown, including the distribution suffix, because a typo means apt cannot find the version and the command fails. Pinning to the candidate works on its own, since apt resolves nginx-common to the same candidate build. Pinning to anything older than the candidate is a different story. The sibling packages still resolve to their newest build, so you have to pin them too, as Step 6 shows.

On the web01 box the string we pinned, 1.24.0-2ubuntu7.21, sits on the first line of the list, flagged as upgradable from the installed release build.
Step 5: Hold a Package to Prevent Upgrades
After upgrading to a tested version, you may want to lock it in place so future apt upgrade runs do not change it. The apt-mark hold command prevents a package from being upgraded, removed, or modified. This is useful for managing package repositories where you have added third-party sources and need to control which versions get installed. Hold nginx-common with it, since holding only one half of a lockstep pair lets the other half block or break the next upgrade:
sudo apt-mark hold nginx nginx-common
apt-mark confirms each package separately.
nginx set on hold.
nginx-common set on hold.
To verify which packages are currently held:
apt-mark showhold
Both names come back, one per line.
nginx
nginx-common
Here is what a held package looks like during a full upgrade. On the test VM, nginx was held on the older 1.24.0-2ubuntu7 build, and --assume-no printed the plan then answered no, so nothing changed:
sudo apt upgrade --assume-no
The held pair lands under “kept back” while everything else upgrades.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
nginx nginx-common
The following packages will be upgraded:
krb5-locales libdebuginfod-common libdebuginfod1t64 libdw1t64 libelf1t64
libexpat1 libgssapi-krb5-2 libk5crypto3 libkrb5-3 libkrb5support0
libpcap0.8t64 python3-jwt
12 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
12 standard LTS security updates
Need to get 1256 kB of archives.
After this operation, 18.4 kB of additional disk space will be used.
Do you want to continue? [Y/n] N
Abort.
Seen together in one terminal, the hold and the kept-back list read as cause and effect: two packages held, two packages not upgraded.

When you are ready to allow upgrades again, release the hold:
sudo apt-mark unhold nginx nginx-common
The unhold confirmation reads as follows.
Canceled hold on nginx.
Canceled hold on nginx-common.
Because held packages always show up as “kept back”, you can tell an intentional skip from a dependency problem at a glance. The apt cheat sheet gathers these hold commands together with the rest of the apt and apt-get toolkit, including how the two frontends differ on locking, if you want the whole set on one page.
Step 6: Downgrade a Package to a Previous Version
If an upgrade causes problems, you can roll back to a previous version. The syntax is the same as installing a specific version, so the obvious first attempt names only nginx:
sudo apt install nginx=1.24.0-2ubuntu7
On Ubuntu 24.04 that fails, because the old nginx wants the old nginx-common while apt still plans the newest one:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
nginx : Depends: nginx-common (= 1.24.0-2ubuntu7) but 1.24.0-2ubuntu7.21 is to be installed
E: Unable to correct problems, you have held broken packages.
Ignore the “held broken packages” wording, since nothing was on hold at this point. apt won’t pick an older nginx-common by itself while a newer candidate exists, so it reports the conflict and stops.

The fix is to pin every package in the lockstep group to the same old version in one command:
sudo apt install nginx=1.24.0-2ubuntu7 nginx-common=1.24.0-2ubuntu7
apt now lists both packages under DOWNGRADED and asks before touching anything:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
fcgiwrap nginx-doc ssl-cert
The following packages will be DOWNGRADED:
nginx nginx-common
0 upgraded, 0 newly installed, 2 downgraded, 0 to remove and 12 not upgraded.
Need to get 0 B/552 kB of archives.
After this operation, 7168 B disk space will be freed.
Do you want to continue? [Y/n]
There’s no authentication warning in that prompt, and there shouldn’t be. Both builds come from the signed Ubuntu archive, so apt verified them like any other package, and the only signal of a rollback is the DOWNGRADED heading and the “2 downgraded” count. If you ever see “The following packages cannot be authenticated” during a downgrade, stop, because it means the version you asked for came from a source apt could not verify, which is a repository key problem rather than a downgrade problem.

Scripts need one more flag. Adding -y to the same command is not enough, because apt refuses unattended downgrades:
sudo apt install -y nginx=1.24.0-2ubuntu7 nginx-common=1.24.0-2ubuntu7
The plan prints as before, then the run ends with an error and no change.
The following packages will be DOWNGRADED:
nginx nginx-common
0 upgraded, 0 newly installed, 2 downgraded, 0 to remove and 12 not upgraded.
E: Packages were downgraded and -y was used without --allow-downgrades.
Add --allow-downgrades to make the downgrade go through in automation:
sudo apt install -y --allow-downgrades nginx=1.24.0-2ubuntu7 nginx-common=1.24.0-2ubuntu7
After downgrading, hold both packages immediately to prevent apt from upgrading them back on the next run:
sudo apt-mark hold nginx nginx-common
If the older version is no longer available in your repositories (the Step 2 table only shows the release build and the newest update), download the .deb files from the package’s Launchpad publishing history on Ubuntu or from snapshot.debian.org on Debian and install the matching pair directly with dpkg:
sudo dpkg -i nginx_1.24.0-2ubuntu7_amd64.deb nginx-common_1.24.0-2ubuntu7_all.deb
Because dpkg skips dependency resolution, run sudo apt -f install afterward if it reports missing dependencies.
Step 7: Upgrade from a Specific Repository
When you have multiple repositories providing the same package (for example the default Ubuntu archive and a third-party PPA or vendor repo), you can tell apt to pull specifically from one release. Use the -t flag followed by the release name.
sudo apt install -t noble-security nginx
This forces apt to prefer the version from the noble-security pocket regardless of version priority. It is particularly useful when you want to grab a security fix before it lands in the regular updates channel.
On Debian systems, the release names follow the same pattern:
sudo apt install -t bookworm-backports nginx
Check which releases are configured on your system with:
apt policy | grep -E "release|http"
The release names this prints, such as noble-security or bookworm-backports, are exactly the values the -t flag accepts.
Step 8: Simulate an Upgrade with Dry Run
Before applying changes to a production system, simulate the upgrade to see exactly what apt would do without modifying anything. The --dry-run flag (also available as -s or --simulate) shows the full plan, and it doesn’t need root, so you can run it as your normal user.
apt install --only-upgrade --dry-run nginx
Without root, apt opens with a note that this is only a simulation, then prints the plan with “Inst” and “Conf” lines in place of the real unpack and configure steps:
NOTE: This is only a simulation!
apt needs root privileges for real execution.
Keep also in mind that locking is deactivated,
so don't depend on the relevance to the real current situation!
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
nginx-common
Suggested packages:
fcgiwrap nginx-doc ssl-cert
The following packages will be upgraded:
nginx nginx-common
2 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Inst nginx [1.24.0-2ubuntu7] (1.24.0-2ubuntu7.21 Ubuntu:24.04/noble-updates, Ubuntu:24.04/noble-security [amd64]) [nginx-common:amd64 ]
Inst nginx-common [1.24.0-2ubuntu7] (1.24.0-2ubuntu7.21 Ubuntu:24.04/noble-updates, Ubuntu:24.04/noble-security [all])
Conf nginx (1.24.0-2ubuntu7.21 Ubuntu:24.04/noble-updates, Ubuntu:24.04/noble-security [amd64])
Conf nginx-common (1.24.0-2ubuntu7.21 Ubuntu:24.04/noble-updates, Ubuntu:24.04/noble-security [all])
Each Inst line shows the version on disk in square brackets and the target build in parentheses, so you can read every version transition before you commit. Running the same command with sudo prints the identical plan minus the NOTE block, since the warning only exists to tell a non-root user that apt skipped its lock. That missing lock is the one caveat. If another apt process is running, the simulated plan can be stale, so re-run it right before the real upgrade on a busy host.

A dry run answers “what would this command do”. To see which packages have a newer candidate in the first place, list them instead. This is a read of the package index, not a simulation:
apt list --upgradable 2>/dev/null
Our 24.04 VM had 14 entries, nginx and nginx-common among them.
Listing... Done
krb5-locales/noble-updates,noble-security 1.20.1-6ubuntu2.12 all [upgradable from: 1.20.1-6ubuntu2.10]
libdebuginfod-common/noble-updates,noble-security 0.190-1.1ubuntu0.2 all [upgradable from: 0.190-1.1ubuntu0.1]
libdebuginfod1t64/noble-updates,noble-security 0.190-1.1ubuntu0.2 amd64 [upgradable from: 0.190-1.1ubuntu0.1]
libdw1t64/noble-updates,noble-security 0.190-1.1ubuntu0.2 amd64 [upgradable from: 0.190-1.1ubuntu0.1]
libelf1t64/noble-updates,noble-security 0.190-1.1ubuntu0.2 amd64 [upgradable from: 0.190-1.1ubuntu0.1]
libexpat1/noble-updates,noble-security 2.6.1-2ubuntu0.7 amd64 [upgradable from: 2.6.1-2ubuntu0.6]
libgssapi-krb5-2/noble-updates,noble-security 1.20.1-6ubuntu2.12 amd64 [upgradable from: 1.20.1-6ubuntu2.10]
libk5crypto3/noble-updates,noble-security 1.20.1-6ubuntu2.12 amd64 [upgradable from: 1.20.1-6ubuntu2.10]
libkrb5-3/noble-updates,noble-security 1.20.1-6ubuntu2.12 amd64 [upgradable from: 1.20.1-6ubuntu2.10]
libkrb5support0/noble-updates,noble-security 1.20.1-6ubuntu2.12 amd64 [upgradable from: 1.20.1-6ubuntu2.10]
libpcap0.8t64/noble-updates,noble-security 1.10.4-4.1ubuntu3.2 amd64 [upgradable from: 1.10.4-4.1ubuntu3.1]
nginx-common/noble-updates,noble-security 1.24.0-2ubuntu7.21 all [upgradable from: 1.24.0-2ubuntu7]
nginx/noble-updates,noble-security 1.24.0-2ubuntu7.21 amd64 [upgradable from: 1.24.0-2ubuntu7]
python3-jwt/noble-updates,noble-security 2.7.0-1ubuntu0.6 all [upgradable from: 2.7.0-1ubuntu0.5]
Use this list to pick the one package you want, then dry-run that package as shown above. When you want a preview of the whole-system upgrade instead, sudo apt upgrade --assume-no prints the full plan and answers no for you, the same way Step 5 showed the held packages being kept back.
Step 9: Auto-remove Unused Dependencies
When packages are upgraded or removed, their dependencies sometimes become orphaned, installed but no longer required by any package. These waste disk space and increase your attack surface. Clean them up with autoremove.
sudo apt autoremove
apt lists orphaned packages and their total disk usage before asking for confirmation:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
linux-headers-6.8.0-38 linux-headers-6.8.0-38-generic linux-image-6.8.0-38-generic
linux-modules-6.8.0-38-generic linux-modules-extra-6.8.0-38-generic
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation, 423 MB disk space will be freed.
Do you want to continue? [Y/n]
Old kernel packages are the most common orphans. Running autoremove after kernel upgrades keeps /boot from filling up, which is a common issue on systems with a small boot partition. If you manage a local Ubuntu mirror, unused dependencies also waste mirror disk space.
To also remove cached package files that are no longer available in repositories:
sudo apt autoclean
Between autoremove and autoclean, a long-running server stays free of both orphaned packages and stale cached archives.
apt Version Management Commands Reference
This table summarizes all the commands covered in this guide for quick reference when managing package versions on Ubuntu and Debian systems.
| Command | Description |
|---|---|
apt list --installed 2>/dev/null | grep pkg | Check installed version of a package |
dpkg -l pkg | Show detailed package info and status |
apt policy pkg | Show installed and all available versions |
apt list -a pkg | List all available versions from repositories |
sudo apt install --only-upgrade pkg | Upgrade a single package only if installed |
sudo apt install pkg=version | Install or upgrade to a specific version |
sudo apt install pkg=old pkg-common=old | Downgrade a lockstep package pair together |
sudo apt install -y --allow-downgrades pkg=old | Downgrade non-interactively in scripts |
sudo apt-mark hold pkg | Prevent package from being upgraded |
sudo apt-mark unhold pkg | Release a held package for upgrades |
apt-mark showhold | List all held packages |
sudo apt install -t release pkg | Install from a specific repository release |
apt install --only-upgrade --dry-run pkg | Simulate upgrade without making changes (no root needed) |
apt list --upgradable | List packages that have a newer candidate |
sudo apt autoremove | Remove orphaned dependencies |
sudo apt autoclean | Remove obsolete cached packages |
Conclusion
You now have full control over individual package upgrades on Ubuntu and Debian. The --only-upgrade flag handles targeted updates, apt-mark hold locks packages at a known-good version, and --dry-run lets you preview every change before committing. On production systems, always simulate first, upgrade one package (and its lockstep siblings) at a time, and hold critical packages after verifying your repository keys are current and your package sources are trusted.