How to Uninstall or Remove Packages from CentOS

October 4, 2019

Introduction

Uncesscerary packages slow down system performance and take up storage space. If specific software isn’t being used, then it’s best to remove it, and doing so is easy.

In this tutorial, learn how to remove packages and uninstall dependencies from CentOS 7.

Tutorial on how to uninstall packages from CentOS.

Prerequisites

  • Access to a user account with sudo or root privileges
  • A terminal window or command line (Ctrl+Alt+F2)
  • The YUM and RPM package managers, included by default

Uninstall Package from CentOS with Yum

CentOS is an RHEL (Red Hat Enterprise Linux) distribution. Users rely on the RPM (Red-hat Package Manager) and YUM (The Yellowdog Updater, Modified) package manager.

To remove a package from CentOS, use the following yum commands:

yum remove [package_name]

OR

yum erase [package_name]

In the following example, we deleted the Apache web server package, filed under the name httpd.x86_64, using the yum command.

Before removing, the command prompt asks for the root (or sudo user) password, and confirmation that you want the software deleted.

Type in y (for yes) and press Enter. If you have changed your mind, press n (for no) and then Enter.

Finally, the output informs you that the process is complete and shows you which package has been deleted.

software removed from centos with yum remove command

Note: Only root users and users added to the sudousers group have permission to install and remove packages in CentOS.

How to Remove Packages with Dependencies Using Yum

Package dependencies are binaries, libraries, and modules on which software rely on. When installing software, it will automatically download and store the required dependencies.

In most cases, deleting software from the local package manager will also erase its dependencies (unless other programs require them).

Still, there are instances in which these dependencies have to be removed manually.

To remove a package and erase all the unneeded dependencies use the following command:

yum autoremove [package_name]

Note: When a user installs a package, YUM downloads and stores it in /var/cache/yum. However, packages remain in cache even after they've been installed and removed. In time, the stored cache may take up too much disk space or cause issues due to corrupt metadata. To reclaim disk space, be sure to clean the YUM cache.

Alternatively, you can alter the yum configuration file  to automatically remove package dependencies when deleting a package with the yum remove or yum erase commands.

Start by opening the yum.conf file with a text editor of your choice:

vi /etc/yum.conf

Then, add the following line to the file:

directive clean_requirements_on_remove=1
edit yum confi file for autoremove


Save and exit the file.

How to Find Specific File in CentOS

In case you need to delete a package but are unsure of its exact file name, you can use one of the following two commands:

yum list- | grep [package_name]

OR

rpm -qa | grep [package_name]

The output will list all installed packages with the specified phrase found in the file name.

As you can see in the image below, httpd appears in the following packages (and dependencies):

find package name in centos


After you have the exact name of the package you want to erase, you can uninstall it from your CentOS system.

For more options on listing packages on CentOS read our detailed tutorial.

Conclusion

After reading this tutorial, you should now know how to remove packages and dependencies to free up space taken up by redundant programs.

You also know how quickly find specific packages or files you want to delete.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
How to Use wget Command With Examples
February 14, 2024

Wget is a commonly used tool for downloading files in a command-line session. Not only is it fast and...
Read more
How to Uninstall or Remove Software Packages From Ubuntu
September 4, 2019

This guide will walk you through several methods for removing old or unwanted software from an Ubuntu Linux...
Read more
How to Set Up Local Yum Repositories on CentOS 7
April 29, 2019

In Linux, a repository is a central database of software. Most modern Linux distributions have a central...
Read more
How to List Installed Packages on CentOS with Yum or RPM
April 29, 2019

Managing a CentOS operating system often means knowing the software packages that are installed. This list...
Read more