Skip to content
Search AlmaLinux

    Browse this documentation

    AlmaLinux 9: undo a mistaken dnf install

    Installed the wrong package or version, or removed a dependency by accident? The first move is not “install it back” but dnf’s transaction history: every install, removal and upgrade is recorded with an ID, and undo can reverse one of them.

    Executed in an almalinux:9 container (AlmaLinux 9.8, aarch64, dnf 4.14.0): cat /etc/almalinux-release, dnf --version, dnf repolist --enabled, dnf -y install tree, dnf history list, dnf -y history undo 3, then rpm -q tree. Log: plans/content-expansion/evidence/logs/alma-dnf-history-rollback.log.

    The behaviour of rollback, failures when a version is unavailable, and configuration/service state recovery were not tested here and are labelled as documentation-based.

    Read the transaction ID first — do not assume it starts at 1

    Section titled “Read the transaction ID first — do not assume it starts at 1”
    Terminal window
    dnf history list | head -4
    ID | Command line | Date and time | Action(s) | Altered
    -------------------------------------------------------------------------------
    2 | reinstall -y --installro | 2026-10-02 09:09 | R | 2
    1 | install -y ... | 2026-10-02 09:08 | Install | ...

    The almalinux:9 container image used here already contains transactions from the image build. So to undo “the one you just did”, never hardcode undo 1 — read the list and take the ID that belongs to your operation.

    Terminal window
    sudo dnf -y install tree
    dnf history list | head -3
    ID | Command line | Date and time | Action(s) | Altered
    -------------------------------------------------------------------------------
    3 | -y install tree | 2026-10-18 16:33 | Install | 1

    In this test the new transaction was ID 3 (the first two came with the image). In scripts, dnf history list | awk 'NR==3{print $1}' grabs the newest row.

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

    undo reverses the transaction: transaction 3 installed one package, so the undo removes that package.

    ID | Command line | Date and time | Action(s) | Altered
    -------------------------------------------------------------------------------
    4 | -y history undo 3 | 2026-10-18 16:33 | Removed | 1
    3 | -y install tree | 2026-10-18 16:33 | Install | 1

    The undo is a new transaction too (ID 4 here). In theory undoing 4 puts things back, but that step was not run here (Rocky results are not Alma evidence); run dnf history info 4 first when you need it.

    SituationUse
    Just installed the wrong packagednf history undo <ID>: reverses only that transaction
    Several steps back-to-back, want to go back as a wholednf history rollback <ID>: returns to the state after that transaction
    Only want to see what changeddnf history info <ID>: changes nothing

    Both only cover packages managed by DNF.

    • Hardcoding undo 1: when the image ships transactions, this can revert build-time packages and even hit dependency conflicts (running it against ID 1 here failed with an rtld(GNU_HASH) conflict);
    • Forgetting configuration: files overwritten under /etc are not restored, and systemctl enable symlinks are not part of a transaction;
    • Version no longer available: undo refuses; run dnf history info first, then fetch the version from a vault repository.

    Prerequisite: AlmaLinux 9 with root or sudo.

    Terminal window
    sudo dnf -y install tree
    ID=$(dnf history list | awk 'NR==3{print $1}')
    echo "transaction ID=$ID"
    sudo dnf -y history undo "$ID"

    Checks:

    1. rpm -q tree → package tree is not installed
    2. dnf history list | head -3 → a new history undo row appears
    3. Undo that new row → tree is installed again

    常见问题

    Why does `dnf history undo 1` fail?

    This container image ships build transactions from 2026-10-02, so ID 1 belongs to the image build rather than your command. Undoing it tries to reverse packages installed at build time and failed here with an rtld(GNU_HASH) dependency conflict. Use dnf history list to find your own transaction ID.

    Does undo restore configuration files?

    No. undo only reverses the packages in the transaction; files created or overwritten under /etc are not restored and systemctl enable symlinks are not recorded, so verify configuration and service state afterwards.

    What if I undo the wrong thing?

    Run dnf history info <ID> to see the affected packages, then decide whether to undo the new undo transaction. This requires the package versions to still be available; the undo-of-undo step was not tested on Alma here.