How to use DNF or YUM History to recover from issues

Voiced by Amazon Polly

Accidents can happen at any time on a computer system.  Some small, some painfully large.  One of such accidents can be removing or installing packages in Linux and it causing havoc in your system.  This is when knowing about DNF | YUM History can help you out. This article was originally written years ago on a previous blog of mine. I am adding it back here so others can see how to use dnf history, and benifit from my past experience.

The DNF remove command

When you run a DNF remove command it does list all the packages and dependencies that are going to be removed and gives you the opportunity to abort.  The problem can come into play if you get too complacent and just hit yes, or are just unaware of the impact of the removal of some of those packages on your system.  I had such an incident while troubleshooting audio issues on my Fedora 23 system.  The audio just wouldn’t play, and I thought about removing pulseaudio-7.1 from the system and seeing what would happen as one of my troubleshooting steps, basically to see if that package was causing my issues or not. 

For whatever reason dnf remove pulseaudio removes portions of the gnome-shell, enough of it to break the GUI interface completely.  After the reboot and my system only coming up in the command line my mind flashed back and recalled the word gnome in the list and I figured that was what broke it.

dnf history shows what was done linked to a job ID.

Restoring using DNF History

I wasn’t too worried as I can get around in the command line just fine, but I still wanted my GUI for other reasons as this is a home workstation, not a server.  I recalled a command from my Red Hat training that proved to be very useful in this situation.  DNF History (yum history for CentOS and Red Hat)

You will need to be logged on as root to perform this action of course.  If it won’t fit on the screen just type the command dnf history | less then take note of the ID number on the left of the screen.  The offending removal I had was ID 96.  Then you just type DNF history undo 96 and the system will install all the packages that were removed earlier.  I tried other things while I was there and messed it up a bit more, which is why you see in the screenshot individual gnome installs.  I used the history to see what packages were removed and then did a batch install of them all.  I then finished up with a systemctl set-default and a reboot.


The system came up without incident and the Gnome GUI loaded as it did before I broke the system.  The moral of the story is to first pay attention to what is being removed and to make sure that is REALLY okay.  It is nice to know that the DNF history command is there however, and at some point you just may need to use it.


Ivan Windon

Ivan Windon is a Lead Engineer at Verizon Enterprise Solutions. Ivan is actively engaged in Cloud Technologies with AWS, Google, and Azure. Ivan has extensive experience with Linux and Windows administration, DNS, Networking, IDM, and Security. In his free time, he enjoys being with his wife and two children. The family enjoys hiking, and traveling when able. His favorite locations are Yosemite NPS, and San Francisco, California.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: