To remove a package from CentOS, you use the yum remove command (or dnf remove on CentOS 8 and later). This uninstalls the package and its associated files, but it does not remove dependencies that were automatically installed—those are left behind unless you explicitly clean them up.
Background: YUM and DNF
CentOS has used two main package managers over its lifetime. Older versions (CentOS 6 and 7) rely on YUM (Yellowdog Updater Modified), while CentOS 8 and later use DNF (Dandified YUM), which is the next-generation fork of YUM. DNF was introduced to improve performance, dependency resolution, and to integrate better with Python 3. Most commands are interchangeable—yum remove and dnf remove work the same way—but on CentOS 8+, you should use dnf as the default. On CentOS 7, you can still install DNF, but YUM is the standard.
How to Remove a Package
The basic syntax is:
sudo yum remove package_name
or on CentOS 8+:
sudo dnf remove package_name
For example, to remove the Apache web server on CentOS 7:
sudo yum remove httpd
You will be prompted to confirm the removal. Type y and press Enter. The package manager will then uninstall the package and any files that belong to it, but it will not touch dependencies that other packages still need.
Removing Dependencies and Unused Packages
When you install a package, YUM/DNF often pulls in dependencies automatically. Removing the main package does not remove those dependencies. To clean up orphaned dependencies, use the autoremove command:
sudo yum autoremove
or on CentOS 8+:
sudo dnf autoremove
This removes packages that were installed as dependencies but are no longer required by any installed package. Be careful—if you have manually installed something that was once a dependency, it might get removed if you are not paying attention. Always review the list before confirming.
Removing Multiple Packages at Once
You can remove several packages in one command by listing them separated by spaces:
sudo yum remove httpd php mysql
This is efficient when you are cleaning up a group of related packages. YUM/DNF will resolve the combined dependency tree and remove everything together.
Common Problems and How to Avoid Them
- Package not found: If you get an error saying the package is not installed, double-check the exact name. Use
yum list installed | grep keywordordnf list installed | grep keywordto search. - Removing a critical system package: Some packages are essential for the system to boot or function. YUM/DNF will warn you if you try to remove a package that is required by many others. Do not force removal with
--nodepsunless you know exactly what you are doing—it can break your system. - Configuration files left behind: By default,
removedoes not delete configuration files that were modified by the administrator. If you want to purge them too, you can manually delete them from/etcor useyum remove --purge(not available in all versions). - Dependency conflicts: If another package depends on the one you are removing, YUM/DNF will refuse and show you the dependent packages. You can then decide whether to remove those as well or keep the package.
Comparing YUM and DNF Removal
In practice, the removal process is nearly identical. DNF is faster and uses less memory, and it handles some edge cases better (like broken dependencies). It also provides more informative output. If you are on CentOS 8+, always use dnf. If you are on CentOS 7, stick with yum unless you have installed DNF manually. One notable difference: DNF has a --setopt=clean_requirements_on_remove=true option that automatically removes dependencies when you remove a package. This is off by default to match YUM’s behavior, but you can enable it globally in /etc/dnf/dnf.conf if you prefer.
Safety and Best Practices
- Always use
sudo—package removal requires root privileges. - Review the list of packages that will be removed before confirming. It is easy to accidentally remove something you need.
- Consider using
yum historyordnf historyto undo a removal if something goes wrong. You can roll back a transaction withyum history undo. - If you are removing a package that provides a service, stop the service first with
systemctl stop service_nameto avoid errors. - Back up configuration files you might need later, especially if you plan to reinstall the package.
Alternatives to Removing
Sometimes you do not need to fully remove a package. You can:
- Disable a service: Use
systemctl disable service_nameto prevent it from starting at boot without uninstalling it. - Downgrade: If a newer version is causing problems, use
yum downgrade package_nameto revert to an older version. - Keep configuration: If you plan to reinstall later, you might prefer to just remove the binary files but keep the config. That is not a standard option, but you can manually move config files elsewhere before removal.
Frequently Asked Questions
How do I remove a package and all its dependencies in CentOS?
Use sudo yum autoremove (or sudo dnf autoremove) after removing the main package. This cleans up orphaned dependencies. Alternatively, on DNF you can enable clean_requirements_on_remove=true in /etc/dnf/dnf.conf to do it automatically.
What is the difference between yum remove and yum erase?
They are the same command. yum erase is an alias for yum remove. Both uninstall the package.
Can I remove a package without sudo?
No, removing packages requires root privileges. You must use sudo or be logged in as root.
How do I see what packages are installed?
Use yum list installed or dnf list installed. You can also filter with grep, for example: yum list installed | grep httpd.
What if I accidentally remove an important package?
You can reinstall it with sudo yum install package_name. If you remember the transaction ID, you can also use sudo yum history undo to roll back the entire removal.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Why Game Servers Need DDoS Protection
- Aion2 Banned Account: What to Do
- Turn Company Strategy into Team Priorities
- Embedded Finance for Small Businesses: How It Works
- Best 3D Printer Brands for Budget, Workflow & Detail
- Brother Printer Keeps Going Offline? Fix It Fast