How to Uninstall or Remove Packages from CentOS

Uninstallation or removal of software packages from a CentOS system is a straightforward process, thanks to YUM, the native package management utility for many RHEL-based distributions.

The yum remove package command is a critical tool for system administrators and users, offering a simple yet effective method to manage the software footprint on a CentOS server or workstation. This command ensures that unwanted or unnecessary packages are cleanly and efficiently removed from the system, helping to maintain optimal performance and security. 

In this short tutorial, we will explore the basics of using the yum remove package command, including its syntax and some important considerations to remember when removing software from a CentOS environment. You will see how to effectively use the command to manage the packages on your CentOS system.

Table Of Contents

  1. Uninstall or Remove Packages from CentOS
    1. The Prerequisites
    2. Scenario #1: Remove a Software Package from CentOS Using YUM
    3. Scenario #2: Remove Dependencies With Packages via Yum
    4. Scenario #3: Configure YUM to Automatically Clean Up Dependencies
    5. Scenario #4: Locate a Specific Package in CentOS for Removal
  2. Conclusion
  3. FAQS

Uninstall or Remove Packages from CentOS

Let’s start with trying out the various ways of removing packages from a CentOS system. However, before that, we should take a quick look at the prerequisites for the process.

The Prerequisites

Before trying out the ideas we will discuss later on, make sure you have the following:

  • RHEL-based Systems: We recommend working on a system running an RHEL-based Linux distribution that supports YUM as the package manager. 
  • Appropriate User Permissions: You must have access to an account with root or sudo privileges. This level of access is necessary to execute commands that make system-wide changes, such as removing software packages.
  • Package Management Tools: Ensure that the YUM (Yellowdog Updater, Modified) and RPM (Red Hat Package Manager) tools are installed on your system. In CentOS, these are the default package managers used for all essential software package installations, updates, and removals.

Scenario #1: Remove a Software Package from CentOS Using YUM

CentOS, a distribution built on a stable release of the Red Hat Enterprise Linux (RHEL), utilizes the Red Hat Package Manager (RPM ) and Yellowdog Updater, Modified(YUM) for package management tasks.

To execute the removal of a software package on CentOS, the yum remove package command comes into play, formatted as follows:

# yum remove [package_name]

Alternatively, the same outcome can be achieved using the erase command:

# yum erase [package_name]

Consider the scenario where we need to uninstall the Apache web server (identified by the package name httpd.x86_64). We will run the following command to initiate the process: 

# yum remove httpd.x86_64

During the process, you will be prompted to enter the password for the root or a sudo-enabled user account, followed by a request for confirmation to proceed with the removal. 

To confirm, type y and press Enter. If you decide against the removal, type n and then Enter to abort the operation.

Upon completion, the terminal will display a message indicating the successful removal of the specified package, providing a detailed track of actions taken during the process.

resolving dependencies

Scenario #2: Remove Dependencies With Packages via Yum

Software packages often depend on various binaries, libraries, and modules to function properly. These dependencies are automatically fetched and installed by the package manager during the installation process.

Typically, when a software package is removed from the system using the package manager, its dependencies are also deleted, provided they are not needed by other installed software.

However, there are situations where these dependencies might not be automatically removed. In this case, you might experience compatibility issues and missing package warnings. 

A simple fix of this situation is to comprehensively remove a package and also purge all its unused dependencies. YUM provides a simple command to address this situation:

# yum autoremove [package_name]

This command ensures that the primary package, along with any associated dependencies that are no longer required by other applications, are thoroughly removed from the system.

Do you know that you can manually clear the package index cache in Linux distributions? We have a detailed tutorial on how you can clean the YUM cache in CentOS and other RHEL distributions.

Scenario #3: Configure YUM to Automatically Clean Up Dependencies

An alternative approach to managing package dependencies during removal is to adjust the YUM configuration to automatically handle these dependencies when executing the yum remove or yum erase commands.

The process starts by accessing the yum.conf configuration file in your preferred text editor. We will open the file in Vi by running the following command in the terminal:

# vi /etc/yum.conf

Scroll down and add the following line:

directive clean_requirements_on_remove=1

This directive instructs YUM to automatically eliminate any dependencies that are no longer necessary after a package is removed. This update to the configuration file streamlines the package management process and keeps the system clean of unused software components.

directive clean_requirements_on_remove

After making the changes, remember to save the file before exiting the editor.

Scenario #4: Locate a Specific Package in CentOS for Removal

When working with packages on a CentOS system, you often know the name of the software but not the precise package name (Apache vs httpd_x86.64).

Since YUM and RPM are package managers, you can leverage the capabilities of these components to find out the associated package name. 

Start by running one of the following commands to extract the name of the package from the package index:

# yum list installed | grep [search_term]

or

# rpm -qa | grep [search_term]

These commands use the grep utility to filter through all installed packages and display all package names that match the search term.

For instance, if you’re looking to identify packages related to Apache (httpd), the above command will yield a list of all installed packages where httpd is part of the package name. You can view this list to identify the exact name of the package.

yum list

Once you have identified the name of the package you wish to remove, you can proceed to uninstall it from your CentOS system using the yum remove package command.

Conclusion

Mastering the yum remove command is crucial for efficient software management on CentOS. It simplifies decluttering, boosts performance, and enhances security by eliminating unnecessary or outdated packages. With YUM, handling single packages or dependencies becomes effortless. 

RedSwitches offers customizable bare metal servers with competitive pricing and swift delivery. Whether you need a dedicated server, a 10Gbps traffic-friendly server, or a high-performance bare metal server, we’re your reliable hosting partner.

FAQs

Q. What is the yum remove package command used for in CentOS?

The yum remove package command is utilized to uninstall or remove software packages from a CentOS system. It ensures that the specified package, along with its non-essential dependencies, is deleted from the system.

Q. How can I remove a package without knowing its exact name?

You can locate the package by using the command yum list installed | grep [search_term] or rpm -qa | grep [search_term] to search through installed packages and find the one you intend to remove.

Q. Is it necessary to have root or sudo privileges to use the yum remove package command?

Yes, removing packages affects the system globally; therefore, root or sudo privileges are required to execute the yum remove package command.

Q. Will yum remove package also deletes the dependencies of the package being removed?

yum remove package will remove the specified package and may also remove dependencies that are no longer needed by other packages. To explicitly clean up unneeded dependencies, you can use yum autoremove.

Q. How can I ensure that dependencies are automatically removed when I uninstall a package?

To automatically remove unneeded dependencies, you can add the line clean_requirements_on_remove=1 to your /etc/yum.conf file. This setting instructs yum to clean up dependencies that are not required by any other package upon removal.

Q. What is the difference between yum remove and yum erase?

There is no functional difference between yum remove and yum erase. Both commands perform the same action of uninstalling packages from the system.

Q. Can I remove multiple packages at once using the yum remove package command?

Yes, you can specify multiple package names separated by spaces with the yum remove package command to remove several packages in a single operation.

Q. How can I confirm which packages were removed after executing the yum remove package command?

Upon successful execution, the yum remove package command will display a summary of the actions taken, including a list of removed packages.

Q. Is it possible to undo a package removal using yum?

While yum does not have a direct undo feature, you can reinstall a package using yum install package_name if you need to restore it after removal.

Q. What precautions should I take before removing a package with yum?

Before removing a package, it’s wise to check its dependencies and consider the impact on the system. Backing up important data and ensuring you have root or sudo privileges are also recommended precautions.