Use the yum remove command followed by specific package names to uninstall software on CentOS 7. This action deletes the main files but leaves configuration data behind. To ensure a complete removal of associated settings and cached data, you must manually identify and delete residual configuration files from system directories after the initial package deletion.
Understanding Package Removal vs Purging
It is critical to understand that standard package managers likeyum on CentOS 7 do not perform a "purge" operation in the same way Debian-based systems handle apt purge. When you execute a removal command, the package manager removes the binaries, libraries, and other files installed by the package. However, it intentionally preserves configuration files located in directories such as /etc. This design choice allows administrators to reinstall the software later without losing their custom settings.
If your goal is to completely eliminate all traces of a package, including its configuration files, you cannot rely solely on the package manager. You must combine the automated removal with manual cleanup steps. This distinction is vital for server maintenance, disk space optimization, and ensuring no orphaned configuration files interfere with new installations or security audits. Many users confuse these two processes, leading to confusion when they expect a clean slate after running a simple removal script.
Executing the Removal Command
The primary tool for managing packages on CentOS 7 isyum. While newer versions of Linux distributions have moved toward dnf, CentOS 7 remains firmly rooted in the yum ecosystem. The command structure is straightforward and can be easily integrated into shell scripts for automation.
To remove a single package, use the following syntax:
yum remove package_name
Replace package_name with the actual name of the software you wish to uninstall. For example, to remove the Apache web server, you would type:
yum remove httpd
When you run this command, yum will calculate the dependencies and display a list of packages that will be removed. It often includes the main package along with any dependent packages that are no longer required by other software. Review this list carefully. If there are critical dependencies you want to keep, you may need to adjust your approach or accept that those dependent packages will also be removed.
After reviewing the list, confirm the action by typing y and pressing Enter. The system will then proceed to delete the specified files. If you prefer a non-interactive script, you can add the -y flag to automatically assume yes for all prompts:
yum -y remove package_name
This flag is essential for batch operations or cron jobs where user interaction is not possible. Always test this command in a staging environment first to ensure it does not remove critical system components unexpectedly.
Handling Dependencies and Residual Files
One common pitfall in package management is leaving behind orphaned dependencies. After removing a primary package, other packages that were installed as dependencies might remain on the system if they are still required by other software. To clean up these unused dependencies, you can use the autoremove feature.yum autoremove
This command scans the system for packages that were installed as dependencies but are no longer needed by any currently installed software. It provides a safe way to reclaim disk space and reduce the attack surface of your server by eliminating unnecessary code.
However, yum autoremove does not touch configuration files. As mentioned earlier, configuration files stored in /etc persist even after the binary files are gone. To find these residual files, you can search the /etc directory for directories or files named after the removed package.
For example, if you removed httpd, you might look for:
/etc/httpd//var/log/httpd/
rm command. Be extremely cautious when deleting files in /etc, as incorrect deletions can break other applications that share similar naming conventions or rely on shared system configurations.
Scripting the Process
For system administrators managing multiple servers, automating this process is efficient. A simple bash script can iterate through a list of packages, remove them, and log the results. Below is an example of how such a script might look. Note that we avoid hardcoding paths like/usr/bin/yum to ensure compatibility across different system configurations where yum might be aliased or located differently in the path.
#!/bin/bash
PACKAGES=("pkg1" "pkg2" "pkg3")
for PKG in "${PACKAGES[@]}"; do
echo "Removing $PKG..."
yum -y remove "$PKG" &> /dev/null
# Optional: Check if config files exist
CONFIG_DIR="/etc/$PKG"
if [ -d "$CONFIG_DIR" ]; then
echo "Config directory found at $CONFIG_DIR. Manual review recommended."
fi
done
echo "Removal process completed."
This script loops through an array of package names, executes the removal command silently, and checks for leftover configuration directories. It provides a basic framework that can be expanded with error handling and logging features for production environments.
Verifying Removal
After executing the removal commands, it is good practice to verify that the packages are indeed gone. You can use theyum list installed command to check if a package is still present.
yum list installed | grep package_name
If the package has been successfully removed, this command should return no results. If it still appears, the removal may have failed, or you might be looking at a metapackage that depends on other components. In such cases, investigate further to ensure the core functionality has been uninstalled.
Additionally, check the system logs to ensure no errors occurred during the removal process. Logs are typically stored in /var/log/yum.log. Monitoring these logs helps in troubleshooting unexpected issues and maintaining a clear audit trail of system changes. For advanced setups, consider forwarding these logs to a remote server for centralized monitoring, as discussed in our guide on How to Forward /var/log/yum.log to Remote Logging Server using rsyslog.conf?. This ensures that even if local logs are rotated or deleted, you retain historical data for compliance and debugging purposes.
Frequently Asked Questions
Does yum remove delete configuration files?
No, theyum remove command only deletes the package files themselves. Configuration files located in /etc are preserved to allow for easy reinstallation. You must manually delete these files if you want a complete purge.
What happens to dependencies when I remove a package?
Dependencies that are still required by other installed packages will remain on the system. However, dependencies that are no longer needed can be removed using theyum autoremove command to free up disk space.
Can I automate the removal of residual config files?
While you can write scripts to delete known configuration directories, it is risky to automate this blindly. Different packages may store configs in various locations. It is safer to script the removal of binaries and manually verify or script the deletion of specific, well-known config paths.Why does my yum command fail with 'Could not retrieve mirrorlist'?
This error usually indicates a network connectivity issue or a misconfigured repository source. Ensure your network interface is active and that your/etc/yum.repos.d/ files point to valid mirrors. Troubleshooting steps for this specific error are detailed in our guide on Troubleshooting Yum Installation Error: 'Could not retrieve mirrorlist' on CentOS 7.
Is yum erase different from yum remove?
No,yum erase and yum remove are synonymous commands. They perform the exact same function of uninstalling packages. You can use either interchangeably based on your preference or script consistency.