Roll back a dnf transaction on Rocky Linux 9 (tested)
When to use it
Section titled “When to use it”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.
Test scope
Section titled “Test scope”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.
What the transaction history looks like
Section titled “What the transaction history looks like”Install a package to create something you can roll back:
dnf -y install treerpm -q treednf history listID | Command line | Date and time | Action(s) | Altered------------------------------------------------------------------------------- 1 | -y install tree | 2026-10-18 13:22 | Install | 1The ID is the number you pass to undo; Altered is how many packages the transaction touched.
Reverse the transaction
Section titled “Reverse the transaction”dnf -y history undo 1rpm -q treeRemoved: tree-1.8.0-10.el9.aarch64Complete!
package tree is not installedundo 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.
The undo is itself a transaction
Section titled “The undo is itself a 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 | 1That 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.
undo or rollback?
Section titled “undo or rollback?”| Situation | Use | Why |
|---|---|---|
| Just installed the wrong package | dnf history undo <ID> | Reverses only that transaction — smallest blast radius |
| Several upgrades back-to-back and you want to go back as a whole | dnf history rollback <ID> | Returns to the state after that transaction, reversing everything that came later |
| You only want to see what a transaction did | dnf history info <ID> | Changes nothing — inspect before you decide |
Both commands only cover packages managed by DNF.
What undo cannot bring back
Section titled “What undo cannot bring back”Before starting services again, check at least three things:
- Configuration files:
/etcfiles created or overwritten by the package are not restored; - Service state:
systemctl enablesymlinks 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.
Next steps
Section titled “Next steps”- Repositories and what is enabled by default: Rocky repositories
- Automatic updates:
/en/dnf-automatic/(英文页待补) - Generic package management: the hub’s package management basics