What are the steps to safely undo the last yum upgrade on a Linux server, including identifying the transaction ID and handling potential dependency issues?
If you need to undo the last yum upgrade
, you can use the yum history
command. Follow these steps:
- List the Yum History: Run the following command to see a list of your recent yum transactions:
# sudo yum history #
This will display a table with transaction IDs, the user who ran the command, the date and time, the actions performed, and the number of packages altered.
- Identify the Last Upgrade: Look for the transaction that corresponds to your last
yum upgrade
. It will likely have an “Action(s)” column that includes “Upgrade”. Note the Transaction ID (the number in the first column) of this entry. It’s usually the highest number in the list. - Undo the Last Transaction: Once you have the Transaction ID, you can use the
yum history undo
command followed by the ID:# sudo yum history undo <Transaction_ID> #
Replace
<Transaction_ID>
with the actual ID you noted in the previous step. For example, if the last upgrade’s ID was42
, you would run:# sudo yum history undo 42 #
- Confirm the Undo: Yum will then present you with a summary of the packages that will be downgraded or removed to revert the system to the state before the upgrade. Carefully review this list and type
y
to confirm and proceed with the undo operation. - Reboot (if necessary): Depending on the packages that were upgraded (especially kernel or core libraries), you might need to reboot your server after the undo operation is complete.
Important Considerations:
- Dependencies: Undoing an upgrade can sometimes lead to dependency issues if other packages were also updated to rely on the newer versions. Yum will try its best to resolve these, but you might encounter problems.
- System State: Rolling back an upgrade might not perfectly restore the system to its exact previous state, especially if configuration files were modified by post-upgrade scripts.
- Kernel Updates: If the
yum upgrade
included a kernel update, usingyum history undo
might not automatically revert the active kernel. You might need to select the previous kernel from your bootloader (like GRUB) at startup. - Time Sensitivity: The further in the past the upgrade you’re trying to undo, the higher the chance of encountering issues due to subsequent package installations or updates.
Example: Let’s say the output of yum history
looks like this:
ID | Login user | Date and time | Action(s) | Altered ----------------------------------------------------------------- 45 | root | 2025-04-30 19:15 | Upgrade | 50 44 | root | 2025-04-30 19:10 | Install | 1 43 | root | 2025-04-30 19:05 | Install | 2
To undo the last upgrade (Transaction ID 45), you would run:
# sudo yum history undo 45 #
Proceed with caution when undoing upgrades on a production system, and ensure you have backups if possible.