Linux

How to Roll Back a Bad Package Update on Linux Servers With dnf history and apt

The Back Room Tech Staff · Edited by Aseem Kishore
21 min read

The Back Room Tech is reader-supported. We may earn a commission when you buy through links on our site. Learn more.

A routine update ran overnight, and now nginx, PostgreSQL, or some other service won’t start. DNF on RHEL, Rocky Linux, and AlmaLinux records transactions and can attempt to reverse their package operations with dnf history undo or dnf history rollback. That capability is not a guarantee of supported system recovery. Red Hat says using these history commands to downgrade RHEL system packages is unsupported; check the distribution’s policy before choosing a recovery method. On Debian and Ubuntu, APT and dpkg log package activity, but APT has no native command that reconstructs and reverses an earlier transaction. You find an available previous version with apt-cache policy and install it explicitly with apt install package=version. Treat a downgrade as recovery work: keep a usable backup and validate dependencies, configuration, and service health afterward.

Both paths end the same way. You hold the known-good version so the next update doesn’t break it again, and you confirm the service is healthy. If the problem is a kernel that won’t boot, or the package state is too tangled to unwind, you boot the previous kernel or revert a pre-update snapshot.

Quick Reference: Which Rollback Method to Use

ScenarioRecommended FixApplies To
One DNF transaction changed supported non-system packagesAttempt dnf history undo ID after checking package scope and distro policyDNF systems; RHEL system-package downgrade excluded
Several DNF transactions need reversalAttempt dnf history rollback ID where supported; it may failDNF systems; RHEL system-package downgrade excluded
A selected package needs an older versionExplicit dnf downgrade only where that package/dependency change is supportedCheck distro policy; not a workaround for unsupported system downgrade
RHEL system packages or release-level recoveryRed Hat-approved recovery or a validated backup/snapshot procedureRHEL
apt upgrade broke a serviceapt install package=versionDebian, Ubuntu
Fixed package keeps getting re-upgradeddnf versionlock add / apt-mark holdBoth
Server won’t boot after a kernel updateBoot the previous kernel in GRUB, set it as defaultBoth (GRUB)
Dependencies or configs too tangled to unwindRevert LVM, Btrfs/snapper, or VM snapshotBoth

The dates, transaction IDs, package names, and version strings in sample output and screenshots are illustrative. Some screenshots show other packages or older releases; they demonstrate the command’s output format, not the values to use on your server. Read your own logs and package listings before acting. Never paste a 1.x version or OLD_KERNEL_VERSION literally.

Prerequisites

  • OS: RHEL, Rocky Linux, or AlmaLinux with dnf, or Debian or Ubuntu with apt.
  • Access: Root or sudo on the affected server. For kernel rollback, you also need console access. That means a hypervisor console, IPMI, or a KVM-over-IP device, because SSH is gone if the box won’t boot.
  • Repositories: The previous package version must still be available, either in an enabled repo or in the local package cache.
  • Snapshot path (optional): LVM with free space in the volume group, Btrfs with snapper configured, or a hypervisor such as KVM/libvirt, VMware, or Proxmox.
  • Bootloader: GRUB, for the kernel steps.

dnf, apt, and apt-mark ship with most RHEL-family, Debian, and Ubuntu installations, though minimal or container images may omit them. The dnf versionlock plugin is often not included by default, and the exact package name varies by distribution and DNF generation.

Install it through the virtual provide instead of guessing a package name:

# RHEL-family: install versionlock if `dnf versionlock` reports "No such command"
sudo dnf install 'dnf-command(versionlock)'

Some RHEL-family images already include the plugin, in which case this command reports it’s already installed.

DNF can record transactions when history recording is enabled; inspect the installed DNF generation and distribution configuration rather than assuming a universal default (dnf configuration reference). If recording was disabled for the affected transaction, history-based recovery may be unavailable for that transaction. Previously recorded history is not erased merely by disabling future recording; inspect the actual history before choosing another supported recovery path.

Step 1: Identify the Breaking Package and Check Logs Before You Roll Back

Rolling back blind can swap one outage for another. Spend five minutes confirming which package actually caused the failure.

1.1 Read the service’s own failure output

sudo systemctl status nginx.service
# -u filters to one unit; -b limits output to the current boot
sudo journalctl -u nginx.service -b --no-pager -n 50

Look for a library name, a missing symbol, a changed config directive, or a module that failed to load. An error like undefined symbol or version 'OPENSSL_3.x' not found suggests a library or ABI mismatch; correlate it with package and service changes before attributing the cause.

journalctl -u nginx.service -b output showing the service failing to start with a library or config error after an update

1.2 Match the failure time to recent package changes

On RHEL-family systems:

# Most recently installed or updated packages first
rpm -qa --last | head -n 20

On Debian and Ubuntu, apt and dpkg typically log their activity to files such as these:

# Every apt run with its command line, packages, and timestamps
less /var/log/apt/history.log
# Lower-level per-package changes, including the old -> new versions
grep " upgrade " /var/log/dpkg.log

Expected output from the dpkg log looks like this:

2026-11-30 03:12:44 upgrade libssl3:amd64 3.0.x-1 3.0.y-1
2026-11-30 03:12:47 upgrade nginx:amd64 1.x.a-1 1.x.b-1

Write down the old and new version strings. You’ll need the old one in Step 3. If you find no nearby package activity, widen the log window and check rotated logs, service restart timing, configuration and data changes. That absence reduces confidence in an update as the cause; it does not rule out delayed package-related symptoms.

Step 2: Understand DNF History Reversal and RHEL Support Limits

dnf stores each transaction with an ID, the command that ran, and the packages it installed, upgraded, or removed. That ledger lets dnf attempt the inverse package operations of a transaction (DNF command reference).

RHEL support limit: Red Hat’s RHEL10 history guidance and RHEL9 guidance both exclude history-based system-package downgrades, especially SELinux components, kernels, glibc and related dependencies. Do not use this as a RHEL minor-release downgrade. An explicit downgrade command does not override support policy; use vendor-approved recovery or a validated backup/snapshot procedure when necessary. Rocky and Alma users should check their own release guidance.

2.1 List recent transactions

sudo dnf history list

Expected output:

ID     | Command line             | Date and time    | Action(s)      | Altered
------------------------------------------------------------------------------
    42 | update                   | 2026-11-30 03:10 | Upgrade        |   14
    41 | install htop             | 2026-11-28 15:02 | Install        |    1
    40 | update                   | 2026-11-21 03:10 | Upgrade        |    9

dnf history list also accepts a package name, which can help narrow the output to transactions that likely involved it:

sudo dnf history list nginx

2.2 Inspect the suspect transaction

sudo dnf history info 42

This lists packages in transaction 42 along with version details. Read it all. A 14-package update may include an OpenSSL bump that three other services also depend on.

dnf history info output for a single transaction listing upgraded packages with old and new versions

2.3 Choose undo or rollback

The two commands differ in scope:

  • dnf history undo 42 attempts to reverse only transaction 42; later transactions stay in place. It is not a supported RHEL system-package downgrade mechanism.
  • dnf history rollback 40 attempts to reverse transactions after 40. Missing packages, dependency conflicts or RPM-state changes can prevent completion. It does not restore configuration or data, and the same RHEL system-package restriction applies.

After confirming the operation is supported for the affected packages, select undo for one transaction or rollback for a sequence. Do not select either merely because an update broke a RHEL system component.

# Attempt one permitted transaction reversal; check the RHEL support warning above
sudo dnf history undo 42

dnf prints the proposed downgrades and asks for confirmation. Read the list before typing y. Expected tail of the output:

Downgraded:
  nginx-1:1.x.a-1.el.x86_64   nginx-core-1:1.x.a-1.el.x86_64
Complete!

2.4 Know the documented limits

dnf history isn’t a time machine. These limits matter in production:

  • RPM database drift. If packages were changed outside dnf, for example with rpm -i or rpm -e, the current RPM database no longer matches recorded history. dnf won’t undo a transaction when that state conflicts with what history expects (DNF command reference).
  • Old packages must still exist. Undoing an upgrade means installing the previous build. Many repos keep only the latest build, and dnf clean all empties the local cache.
  • Config files are not necessarily reverted. RPM may leave .rpmnew or .rpmsave files behind, depending on how the package handles config changes. The binaries roll back, but your /etc changes stay as they are.
  • Data isn’t reverted. If a database package ran a schema migration on upgrade, downgrading the binary typically won’t undo the migration.

When undo refuses, dnf’s downgrade command can target a single package instead, if an older build is available:

# Show every version dnf can see, installed and available
sudo dnf list --showduplicates nginx
# Downgrade to a specific version-release
# Paste an exact older nginx package specification shown by the command above
read -r -p 'Exact older nginx package specification: ' nginx_previous
sudo dnf --assumeno downgrade "$nginx_previous"
# Review every proposed package/dependency change, then run without --assumeno only if supported
sudo dnf downgrade "$nginx_previous"

Step 3: Downgrade a Package on Ubuntu and Debian With apt

apt tracks what’s installed and logs what it did, but it has no command that replays the log in reverse. There’s no apt rollback. The workaround is a version-pinned reinstall, documented in apt(8) and the Debian AptCLI wiki.

3.1 Find the versions apt can still install

apt-cache policy nginx

Expected output:

nginx:
  Installed: 1.x.b-1
  Candidate: 1.x.b-1
  Version table:
 *** 1.x.b-1 500
        500 http://deb.example.org stable-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     1.x.a-1 500
        500 http://deb.example.org stable/main amd64 Packages

The *** marks the installed version. Other versions are possible candidates, not automatically safe downgrade targets. Check architecture, epoch, repository priority, pinning and matching dependencies before choosing one. If the old version from your dpkg log isn’t listed, check /var/cache/apt/archives/ for a cached .deb. If it’s gone from both, skip to the snapshot path in Step 6.

apt-cache policy output showing the installed version marked with *** and an older version available in the version table

3.2 Reinstall the known-good version

# package=version installs that exact version, even if it's older
read -r -p 'Previous nginx version from apt-cache policy: ' nginx_previous
sudo apt install "nginx=$nginx_previous"

APT may warn about a downgrade and request confirmation; the prompt and resolver behavior vary by version and configuration. If the package depends on exact versions of sibling packages, apt will refuse or try to remove things. In that case, pin the whole set on one line:

# Check both packages with apt-cache policy and select compatible versions
read -r -p 'Previous nginx version: ' nginx_previous
read -r -p 'Matching nginx-common version: ' nginx_common_previous
sudo apt install "nginx=$nginx_previous" "nginx-common=$nginx_common_previous"

Warning: If apt’s proposed solution includes removing packages you didn’t name, answer n. A downgrade that pulls out half your stack is worse than the original bug. Use the snapshot path instead.

3.3 Resolve conffile leftovers

dpkg keeps your edited config and saves the package’s version alongside it, or the reverse. Look for these:

sudo find /etc \( -name "*.dpkg-old" -o -name "*.dpkg-dist" -o -name "*.dpkg-new" \) -print

Diff each one against the live file before restarting the service.

Step 4: Pin or Hold the Package So It Stays Rolled Back

Without an appropriate lock or hold, a later update may select the newer package again. Repository availability, dependency resolution, priorities, exclusions and automation policy determine whether that happens; DNF and APT do not use identical selection rules.

4.1 RHEL-family: dnf versionlock

The linked versionlock documentation says add resolves installed packages first; only if none match does it use available packages. Confirm the installed package before locking it, then inspect the resulting lock rather than assuming its exact syntax:

# Inspect the installed NEVRA (name, epoch, version, release, architecture)
sudo dnf repoquery --installed nginx
# With nginx installed, lock that installed version
sudo dnf versionlock add nginx
# Confirm the lock
sudo dnf versionlock list

Expected output:

nginx-1:1.x.a-1.el.*

When upstream ships a fixed build, remove the lock with sudo dnf versionlock delete nginx. The versionlock plugin docs cover exclude-style locks if you’d rather block one specific bad version. For a broader look at how dnf’s CLI compares to legacy tools, the DNF CLI vs YUM comparison is a useful reference.

4.2 Debian/Ubuntu: apt-mark hold

sudo apt-mark hold nginx nginx-common
apt-mark showhold

Expected output:

nginx
nginx-common

A hold affects normal package resolution; an explicit administrative override, such as apt-get’s documented --ignore-hold, can bypass it. Holding one package also doesn’t make incompatible sibling dependencies safe, so keep the required set consistent. Release it later with sudo apt-mark unhold nginx nginx-common (apt-mark(8)). The trade-off for both tools is the same. A held package also misses security fixes, so put an expiry date on the hold in your ticket and actually revisit it.

Step 5: Roll Back to a Previous Kernel

A bad kernel is a separate failure mode. The userspace packages are fine, but the new kernel lacks a driver or module your hardware or VM needs. You don’t uninstall anything here. An older kernel is a fallback only if it is still installed. Check your installed kernel packages and ls -1 /boot/vmlinuz* before rebooting, and confirm that the matching boot files exist. Cleanup policies, provider images, and local configuration can remove older kernels. If no known-good kernel is available, stop and arrange another recovery path and console access.

5.1 Boot the previous kernel from GRUB

From the console, reboot and interrupt GRUB. On many server installs the menu is hidden, so hold Shift (BIOS) or tap Esc (UEFI) during boot. Choose Advanced options for Ubuntu on Ubuntu, or pick the second entry directly on RHEL-family systems. Select the previous kernel version.

GRUB boot menu on a server console listing the newest kernel and the previous kernel entry

Once it’s up, confirm what you’re running:

uname -r

5.2 Check your RHEL-family kernel-default mechanism

Where your distribution documents grubby for this installation, confirm the command is installed before using it. Boot layout and distribution support vary; if it is unavailable, use that release’s documented kernel-default procedure.

# Show the current default kernel
sudo grubby --default-kernel
# Set the older kernel as default (use the real path from /boot)
read -r -p 'Exact older installed kernel path from /boot: ' previous_kernel
# Do not proceed if the path does not exist
[ -f "$previous_kernel" ] && sudo grubby --set-default "$previous_kernel"

5.3 Make it the persistent default on Debian and Ubuntu

Debian and Ubuntu typically support a persistent default through GRUB_DEFAULT=saved and grub-set-default, but this depends on the GRUB environment block (usually /boot/grub/grubenv) being present and writable. Exact behavior and menu paths also vary by release, so treat the following as a starting point rather than a guaranteed fix.

Edit /etc/default/grub and set:

# /etc/default/grub
GRUB_DEFAULT=saved

Then save the entry and regenerate the config:

# First verify grub-set-default is installed and the GRUB environment block is writable.
# Otherwise stop and use the distribution-supported boot selection procedure.
# Ubuntu entry titles shown in the menu; quote the full submenu path
read -r -p 'Exact GRUB submenu>entry path: ' previous_grub_entry
sudo grub-set-default "$previous_grub_entry"
sudo update-grub

Confirm the saved entry actually took before you trust it:

sudo grub-editenv list

Check saved_entry= against the selected entry; it may contain a title, identifier or encoded menu-entry form rather than the literal title. Menu entry titles differ between Debian and Ubuntu releases, so copy the exact text from grep menuentry /boot/grub/grub.cfg rather than typing it by hand.

If grub-editenv shows no saved entry, or the layout doesn’t use a GRUB environment block, selecting the kernel manually at each boot from the GRUB menu is the more reliable fallback. Either way, test the change with a controlled reboot while you still have console access, not during an unattended restart. Hold the new kernel package with the commands from Step 4 until a fixed version lands.

Warning: Don’t remove the broken kernel until the old one has survived at least one clean reboot. If you delete the wrong one, you’re left with zero bootable kernels.

Step 6: Fall Back to a Snapshot When Package Rollback Isn’t Enough

Snapshots can restore the filesystem, subvolume, or VM state they actually captured. Configs and data on separate or excluded volumes need their own recovery plan; a snapshot is not automatically a backup of the whole server. They’re also blunt. Anything written after the snapshot, including logs and database rows, goes away too.

Choose a snapshot over package rollback when the old package version is gone from every repo, when the dependency resolver wants to remove unrelated packages, or when the update ran migrations against your data.

6.1 LVM snapshot

The commands below assume a conventional layout with a logical volume named root in volume group vg0, and a 10GB snapshot size that fits your environment, not a universal size. These are illustrative commands, not ready-to-run defaults. Replace every volume, group and snapshot name with a verified value from your own layout and choose sufficient snapshot capacity before running any write command. Check your actual names and available space first:

# Confirm volume names and the free space available in the volume group
sudo lvs
sudo vgs vg0

Take a snapshot before updating, sized for how much data will change during the maintenance window:

# -s creates a snapshot; -L sets copy-on-write space for changed blocks
sudo lvcreate -s -L 10G -n root_preupdate /dev/vg0/root

A snapshot of the root volume alone won’t cover /boot, /home, or database volumes if those live on separate logical volumes. Snapshot each volume you need to revert together, and if a database is involved, flush and lock writes first, or use the database’s own backup tooling, so the snapshot is consistent rather than a mid-transaction mess.

Stop before any root-volume merge unless the exact recovery procedure has been validated for your installation. This is a generic LVM snapshot example, not a distribution-approved whole-server rollback procedure. Identify whether the snapshot is regular copy-on-write or thin-provisioned, verify filesystem/layout support and the origin’s activation state, and confirm a supported rescue or maintenance environment with console access. Review separate coverage for /boot, data volumes and bootloader state before choosing recovery.

The upstream lvconvert manual documents distinct snapshot merge operations and activation conditions. Use your distribution’s documented procedure for the verified snapshot type; there is no safe universal root-merge command to paste here. If any prerequisite is unknown, stop and recover through a validated backup or vendor-supported process. Regular copy-on-write snapshot capacity must also be monitored because exhaustion can invalidate the snapshot.

6.2 Btrfs with snapper

On Btrfs filesystems, Snapper is a common tool for creating and rolling back snapshots, but it requires an existing root Snapper config tied to a supported subvolume layout with the distribution’s required boot integration already set up. Run sudo snapper list-configs first; if root isn’t listed, Snapper rollback isn’t available on this system and you’ll need a different fallback.

# Create a labeled pre-update snapshot of the root config
sudo snapper -c root create --description "pre-update 2026-11-30"
sudo snapper -c root list

The snapshot number in the examples below (15) is a placeholder. Use snapper -c root list to find the actual pre-update snapshot number on your system, and confirm its timestamp matches before acting on it.

For root-system recovery, use the distribution’s supported snapshot-boot and rollback procedure for this exact Btrfs layout. On systems supporting it, boot and inspect the chosen snapshot before requesting rollback and follow the required reboot steps. This does not cover separate or excluded filesystems, bootloader state or application data automatically. See the current SUSE Snapper recovery manual for its supported snapshot-boot procedure; other distributions need their own documented integration. If your distro has no supported root rollback procedure, use the validated VM snapshot or backup recovery path instead.

# Read-only inspection of changes between two snapshots; use actual snapshot IDs
sudo snapper -c root status 15..16

Do not use an unrestricted undochange operation to restore every file on a live root filesystem. It is a file-level, non-atomic operation, not a supported substitute for system rollback. Selected-file recovery requires a separate, reviewed procedure appropriate to the distribution.

snapper -c root list output showing a pre-update snapshot with its number, date, and description

6.3 Hypervisor snapshots

Before a revert, verify that the named snapshot exists in the hypervisor’s snapshot inventory and covers the intended disks and configuration. The guest names and IDs below are examples. For stateful services, follow the hypervisor and application’s documented stop or quiesce procedure before creating or restoring a snapshot; external storage and application consistency need separate checks. A revert can discard guest data written since the snapshot.

# libvirt/KVM
sudo virsh snapshot-create-as web01 preupdate
sudo virsh snapshot-revert web01 preupdate
# Proxmox VE
sudo qm snapshot 101 preupdate
sudo qm rollback 101 preupdate

For VMware, use the snapshot-revert procedure documented for your exact product and release rather than assuming one menu path applies everywhere. VM snapshots are the broadest net, and the easiest to forget about. Long-lived snapshots grow and slow disk I/O, so delete them once the update is confirmed good. Size power protection for the hypervisor host’s actual load and required runtime; this runbook doesn’t establish a particular unit’s suitability or price.

Step 7: Verify Service Health and Document the Rollback

A clean Complete! from dnf proves the packages changed. It doesn’t prove the service works.

# Confirm the expected version is installed
rpm -q nginx          # RHEL-family
dpkg -l nginx         # Debian/Ubuntu
# Confirm the service is running and stays running
sudo systemctl restart nginx.service
sudo systemctl is-active nginx.service
sudo journalctl -u nginx.service -b --since "10 minutes ago" --no-pager

Expected output from systemctl is-active:

active

Then test the thing users actually hit. Request the site, run a query, or check your monitoring dashboard. On RHEL-family systems, also run sudo find /etc \( -name "*.rpmnew" -o -name "*.rpmsave" \) -print and resolve what you find.

Document four things in your ticket or runbook: the dnf transaction ID or dpkg log lines, the bad and good versions, the exact rollback command, and the lock or hold you placed with a review date. That record is what stops a colleague from running apt-mark unhold next month without knowing why it’s there.

Step 8: FAQ

Does apt have a rollback command like dnf history rollback?

No. apt typically logs operations to a file such as /var/log/apt/history.log, but it can’t replay them in reverse. Use apt-cache policy to find the old version and apt install package=version to reinstall it.

Why does dnf history undo fail when the transaction looks simple?

Usually the old package is gone from every enabled repo, or something changed the RPM database outside dnf. Run dnf list --showduplicates package to check availability, then fall back to dnf downgrade or a snapshot.

Will rolling back a database package restore my data?

No. Package rollback swaps binaries only, and generally does not reverse schema migrations or other data changes it may have triggered. If the upgrade migrated data files, you need a database backup or a pre-update snapshot.

Does this cover major-version upgrades like RHEL 8 to 9?

No. Major-version in-place upgrades with Leapp are a different process with their own rollback story—see How to Upgrade RHEL 9 to RHEL 10 In Place with Leapp for that workflow. This runbook covers updates within a release.

Should I just snapshot before every update?

Consider a pre-update snapshot when your VM or Btrfs setup supports a tested recovery procedure. Allow for application consistency, storage capacity, and the time needed to restore and validate it; a snapshot is not a substitute for a backup. On bare-metal LVM without spare volume group space, a regular backup to a NAS Hard Drive is the realistic substitute. For details on what’s changed in recent dnf releases, the DNF release notes are a handy reference.

Wrapping Up

You can now trace a broken service to an update, evaluate DNF transaction reversal where supported or an explicit APT version change, and validate the recovery. RHEL system-package failures need the supported vendor recovery path, not an assumed history-based downgrade. DNF’s transaction ledger helps diagnosis, but it does not replace a tested backup. apt users get by fine as long as they read dpkg.log first and pin sibling packages together.

StepActionApplies To
1Check logs, match failure time to package changesBoth
2Inspect DNF history and choose a supported recovery pathRHEL system-package history downgrade excluded; check distro policy
3apt-cache policy + apt install pkg=versionDebian, Ubuntu
4dnf versionlock add / apt-mark holdBoth
5Boot previous kernel, set default with grubby or grub-set-defaultBoth (GRUB)
6Revert LVM, snapper, or hypervisor snapshotBoth
7Verify service, resolve config leftovers, documentBoth
8Check the recovery FAQ and snapshot limitsBoth