If you’re not careful, your Linux system will become full of unused and discarded packages you installed a long time ago, and don’t use anymore. What’s worse, often when you install a particular program, it comes with a list of dependencies that get installed along with it. Ideally, you would want to get rid of these dependencies as well. But how do you know which packages were installed at the same time as the ones you want to remove?
In this tutorial, I’ll show you how to find packages you no longer want to use, how to see the commands that installed them, and also which packages were installed at the same time. And finally, how to undo the steps that led to the installation of the package. This way, you always have a clean system with no “fluff”, and no danger of conflicts.
Note: You need root access to run several of the commands here. Make sure the account you’re using has sudo privileges.
Step 1: Get the Exact Name of the Package you Want to Remove
Recently, I wrote a tutorial on how to install Redis on a VPS running WordPress. But what if you don’t want to use it anymore, and want to change to another object caching method – or not use it at all? You shouldn’t just let Redis remain on your system. So you should remove it properly.
But if it’s been a while since you installed Redis, you might not even remember the exact package name! So the first step is to find what you installed. On CentOS, you do this with the following command:
rpm -qa redis
You don’t need to remember the exact package name with the version number. This command will give you the details of the packages you have installed on your system along with the exact version number.
Step 2: See the History of the Package – When was it Installed, and How?
Now that we know what was installed, we use the yum history command to see how the package was installed and when using the following command:
yum history info redis
This will give an output like this:
Here you can see that redis was installed using the “yum install redis” command, and a dependency called “jemalloc” was installed along with it.
Most importantly, the transaction ID is 311. This is the key that we’re going to use to reverse the installation of redis.
Step 3: Undo the Transaction ID
In the previous step, we go to the transaction ID. This is useful because we’re going to use it to reverse the installation of redis in one step. Some packages might have several dependencies installed along with them, and you don’t want to uninstall each of them separately by typing in the exact package names and version numbers.
We see that in the example above, my transaction ID is 311. Now I just reverse it using the following command:
yum history undo 311
Yum will process the command and ask you for confirmation that you DO want to erase everything that was installed with the original command. Click yes, and you’re done!
Step 4: Restart Services that Use the Package
Finally, you should keep in mind that sometimes services live on in memory even after they’ve been uninstalled. So do the following:
- Restart services that use the uninstalled packages (in my example, httpd, and php-fpm)
- Find and kill the running processes
- Stop and disable the services using the “systemctl stop” and “systemctl disable” commands to clean everything up.
That should be everything! Now you know how to completely remove installed packages from CentOS without leaving any residue.
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!