AlmaLinux 9: undo a mistaken dnf install
When to use it
Section titled “When to use it”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.
Test scope
Section titled “Test scope”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”dnf history list | head -4ID | 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.
Install a package and note its ID
Section titled “Install a package and note its ID”sudo dnf -y install treednf history list | head -3ID | Command line | Date and time | Action(s) | Altered------------------------------------------------------------------------------- 3 | -y install tree | 2026-10-18 16:33 | Install | 1In 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.
Reverse it
Section titled “Reverse it”sudo dnf -y history undo 3rpm -q treeRemoved: tree-1.8.0-10.el9.aarch64Complete!
package tree is not installedundo reverses the transaction: transaction 3 installed one package, so the undo removes that package.
The undo records a transaction as well
Section titled “The undo records a transaction as well”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 | 1The 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.
undo or rollback?
Section titled “undo or rollback?”| Situation | Use |
|---|---|
| Just installed the wrong package | dnf history undo <ID>: reverses only that transaction |
| Several steps back-to-back, want to go back as a whole | dnf history rollback <ID>: returns to the state after that transaction |
| Only want to see what changed | dnf history info <ID>: changes nothing |
Both only cover packages managed by DNF.
Common traps
Section titled “Common traps”- 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 anrtld(GNU_HASH)conflict); - Forgetting configuration: files overwritten under
/etcare not restored, andsystemctl enablesymlinks are not part of a transaction; - Version no longer available: undo refuses; run
dnf history infofirst, then fetch the version from a vault repository.
Practice: undo a mistaken install
Section titled “Practice: undo a mistaken install”Prerequisite: AlmaLinux 9 with root or sudo.
sudo dnf -y install treeID=$(dnf history list | awk 'NR==3{print $1}')echo "transaction ID=$ID"sudo dnf -y history undo "$ID"Checks:
rpm -q tree→package tree is not installeddnf history list | head -3→ a newhistory undorow appears- 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.
Next steps
Section titled “Next steps”- Repositories and defaults: AlmaLinux repositories
- Offline installs: Offline package installs
- Conflicting repos (page pending):
/en/repo-priority/