Sometimes, I need to make some changes to Centos like installing and testing some utilities or trying a complex tutorial to install an advanced program for which the outcome is unknown.
How can I revert back to the state before doing changes.
A practical case: I want to install PHP7 besides PHP5.6, there are many tutorials, I want to test each one and if I fail, I want at least to revert back to the previous state.
For production use, the best approach is to have a testing environment where you can test any changes before applying them into production. Having this as a VM of course helps with snapshots and rollbacks.
Another approach is the use of modern file systems like ZFS that also allow to do snapshots or even LVM.
This is best done with in a virtual machine such as VMware or VirtualBox, rather than on physical hardware. Take a snapshot of your virtual machine prior to making any changes, then it's a trivial matter of reverting to your snapshot should you need to revert to your previous state.
Say you install some package:
yum install php
And say that package
php
installs a bunch of dependencies.If you were to simply try to remove package
php
, viayum remove php
, yum will do just that, and leave the most/all of the dependencies on the system since you didn't ask it to remove them as well.Rather, you can use yum to undo a transaction entirely, by invoking
yum history
command.And now undo history ID 41, in this case:
Note, that in some cases, yum won't be able to remove certain packages, if newer updates depend on them, or they are core system packages, etc... but generally, this will "undo" that transaction.
Also note, on Fedora (and soon on CentOS) systems,
dnf
package manager has the same commands, sodnf history
will still work.Last note, this won't undo any config file changes you've made in /etc (it will remove newly installed config files if a package put them there, however). Anything you do to the system will persist, anything the package manager did, will be reverted. If you need a full-system revert capability, then it's best to use a VM and snapshots as others have mentioned.