Skip to content
Search Rocky Linux

    Browse this documentation

    Roll back a dnf transaction on Rocky Linux 9 (tested)

    Installed the wrong package, the wrong version, or removed a dependency by accident? On Rocky, the first move is not “install it back” — it is looking at dnf’s transaction history. DNF records every install, removal and upgrade as a transaction with an ID, and undo can reverse one of them.

    What was actually executed here: installing tree, dnf history list, dnf -y history undo 1, dnf -y history undo 2 and dnf history info 1 in a rockylinux:9 container (Rocky 9.3, dnf 4.14.0). Rocky 9.8 ships dnf 4.20; column widths may differ and that version was not tested here. Everything else (how rollback behaves, failures when a version is unavailable) comes from the DNF documentation and is labelled as such. Raw log: plans/content-expansion/evidence/logs/rocky-dnf-history-rollback.log.

    Install a package to create something you can roll back:

    Terminal window
    dnf -y install tree
    rpm -q tree
    dnf history list
    ID | Command line | Date and time | Action(s) | Altered
    -------------------------------------------------------------------------------
    1 | -y install tree | 2026-10-18 13:22 | Install | 1

    The ID is the number you pass to undo; Altered is how many packages the transaction touched.

    Terminal window
    dnf -y history undo 1
    rpm -q tree
    Removed:
    tree-1.8.0-10.el9.aarch64
    Complete!
    package tree is not installed

    undo reverses the transaction: transaction 1 installed exactly one package, so the undo removes that package. It does not restore a point-in-time snapshot — it only handles the packages in that transaction.

    ID | Command line | Date and time | Action(s) | Altered
    -------------------------------------------------------------------------------
    2 | -y history undo 1 | 2026-10-18 13:22 | Removed | 1
    1 | -y install tree | 2026-10-18 13:22 | Install | 1

    That is useful: the undo can be undone. If you reverse the wrong transaction, dnf history undo 2 puts it back. Transaction 1 never leaves the history.

    SituationUseWhy
    Just installed the wrong packagednf history undo <ID>Reverses only that transaction — smallest blast radius
    Several upgrades back-to-back and you want to go back as a wholednf history rollback <ID>Returns to the state after that transaction, reversing everything that came later
    You only want to see what a transaction diddnf history info <ID>Changes nothing — inspect before you decide

    Both commands only cover packages managed by DNF.

    Before starting services again, check at least three things:

    • Configuration files: /etc files created or overwritten by the package are not restored;
    • Service state: systemctl enable symlinks are not part of a DNF transaction;
    • Data directories: databases, application data and logs are untouched by undo.

    常见问题

    Can `dnf history undo` revert configuration file changes?

    No. undo only reverses the packages in the transaction (install/remove/upgrade); configuration files created or overwritten under /etc are not restored, and `systemctl enable` symlinks are not part of the transaction, so verify the configuration before starting services.

    Can the undo itself be undone?

    Yes. The undo is recorded as a new transaction (ID 2 in this test, action Removed); undoing ID 2 creates ID 3 (action Install) and reinstalls tree — as long as the package version can still be fetched.

    Why does undo fail with a missing package or version?

    Usually because a later upgrade replaced that version and the repository no longer offers it. undo then cannot reverse the transaction and DNF refuses it; run `dnf history info <ID>` to see which packages are involved, then fetch the version from a vault repository or handle it manually. rollback depends on the same version availability and is not a general cure.