How to Remove a Package in Linux: Simple Commands
To remove a package in Linux, use the package manager command like
sudo apt remove package_name for Debian-based systems or sudo yum remove package_name for Red Hat-based systems. Replace package_name with the actual package you want to uninstall.Syntax
Linux uses package managers to install and remove software. The common commands to remove a package are:
- apt (Debian/Ubuntu):
sudo apt remove package_nameremoves the package but keeps configuration files. - apt (Debian/Ubuntu):
sudo apt purge package_nameremoves the package and its configuration files. - yum (CentOS/RedHat):
sudo yum remove package_nameremoves the package and dependencies no longer needed. - dnf (Fedora):
sudo dnf remove package_namesimilar to yum but for newer Fedora versions.
Replace package_name with the exact name of the package you want to remove.
bash
sudo apt remove package_name sudo apt purge package_name sudo yum remove package_name sudo dnf remove package_name
Example
This example shows how to remove the package vim using apt on a Debian-based system.
bash
sudo apt remove vim
Output
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
vim
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 10.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 123456 files and directories currently installed.)
Removing vim (2:8.1.2269-1ubuntu5) ...
Processing triggers for man-db (2.9.1-1) ...
Common Pitfalls
Common mistakes when removing packages include:
- Using the wrong package name. Always check the exact package name with
apt list --installedoryum list installed. - Not using
sudo, which is required for permission to remove packages. - Confusing
removeandpurgein apt;removekeeps config files,purgedeletes them. - Removing essential system packages accidentally, which can break your system.
Always double-check the package name and the list of packages that will be removed before confirming.
bash
sudo apt remove vim # vs sudo apt purge vim
Quick Reference
| Command | Description | Use Case |
|---|---|---|
| sudo apt remove package_name | Removes package but keeps config files | Debian/Ubuntu systems |
| sudo apt purge package_name | Removes package and config files | Debian/Ubuntu systems |
| sudo yum remove package_name | Removes package and unused dependencies | CentOS/RedHat systems |
| sudo dnf remove package_name | Removes package and unused dependencies | Fedora systems |
Key Takeaways
Use the correct package manager command for your Linux distribution.
Always run removal commands with sudo for proper permissions.
Check the exact package name before removing to avoid mistakes.
Use 'purge' in apt to remove configuration files along with the package.
Review the list of packages to be removed before confirming the action.