How to Apt Remove Package Using Apt Package Manager[2 Proven Methods]


To apt remove package with Apt package manager, you can try these methods:

  1. Uninstalling Single Packages: Uninstall specific software with Apt, including options to retain configuration files (apt remove) or perform a clean removal (apt purge).
  2. Batch Uninstalling Multiple Packages: Efficiently remove multiple packages simultaneously using a text file sudo xargs apt remove < package_list.txt.

Continue reading the guide below to learn two different methods to apt uninstall packages with Apt package manager. Also learn how to revert installation and tips for enhanced productivity.

Managing your Debian system can get tricky when unused packages start to clutter your space. In this post, I’ll show you how to uninstall or remove packages effectively. You’ll learn step-by-step methods using commands like apt remove and apt purge, and even how to batch uninstall multiple packages with xargs. Plus, I’ll share tips on removing leftover configuration files, reverting uninstalls, and using advanced Apt features. Let’s keep your system clean, efficient, and running smoothly together.

Importance of Proper Package Removal

Removing packages correctly is crucial for several reasons:

  1. Avoid System Bloat: Over time, unused packages can pile up and take up space. Properly removing these packages keeps your system clean and free of unnecessary files.
  2. Improve Performance: Excessive, unused packages can slow down your system. Removing them can help maintain optimal performance.
  3. Enhance Stability: Unused or outdated packages can sometimes cause conflicts or errors. Removing these packages can help ensure your system runs smoothly.
  4. Free Up Disk Space: Packages, especially large ones, can take up a lot of disk space. By removing unnecessary packages, you can free up valuable storage space.
  5. Security: Old packages may have security vulnerabilities. Removing these reduces potential security risks.

How to Apt Remove Package With Apt Package Manager

To apt uninstall package with Apt Package Manager, use the sudo apt remove package_name command to remove a package while keeping its configuration files. If you want to remove the package and its configuration files completely, use sudo apt purge package_name. For batch uninstallation, create a text file with package names and use sudo xargs apt remove < package_list.txt. This keeps your system clean and efficient.

Prerequisites for Uninstalling Packages

Before you start uninstalling packages, make sure you have the following in place:

  • Root Privileges: You need administrative rights to remove packages. Use sudo before your commands to get the necessary permissions.
  • Updated Package Lists: Always update your package lists to make sure you’re working with the latest information. Run sudo apt update to update the package lists.
  • Identify the Package: Know the exact name of the package you want to remove. Use commands like apt list --installed to see all installed packages.
  • Backup Important Data: Before removing packages, especially critical ones, make sure to back up any important data to prevent accidental loss.
  • Check Dependencies: Understand what other packages depend on the one you’re removing. This helps avoid breaking your system by accidentally removing something important. Use apt-cache depends package_name to check dependencies.

1. Uninstalling Single Packages

Uninstalling a single package with Apt is a straightforward process that comes in handy when you want to tidy up your system by removing specific software. Follow these steps:

  1. Press Ctrl + Alt + T to open the Terminal.
opening terminal 33
  1. Use the following command to verify the package name and description before removal:
apt show package_name
  1. This command will display detailed information about the specified package, including its name, version, description, and other relevant details.
verifying package name 1
  1. To remove the package without deleting its configuration files, use the apt remove command followed by the package name:
sudo apt remove package_name
  1. This command will uninstall the specified package from your system while retaining its configuration files
deleting package without deleting its configuration files
  1. If you want to completely remove the package, including its configuration files, use the apt purge command:
sudo apt purge package_name
  1. This command will not only uninstall the package but also delete its configuration files, freeing up disk space and ensuring a clean removal.
deleting package along with its configuration files
  1. After removing a package, you can automatically remove any residual dependencies that are no longer required using the apt autoremove command:
sudo apt autoremove
  1. This command will identify and uninstall any packages that were automatically installed as dependencies but are no longer needed, helping to keep your system clutter-free.
deleting any residual unnecesary dependencies

2. Batch Uninstalling Multiple Packages

When it comes to a more comprehensive cleanup or uninstalling multiple packages simultaneously, Apt provides an efficient solution through batch uninstallation. This time-saving method ensures efficient package management while reducing manual effort. Apt provides an efficient way to do this with a single command:

  1. Prepare a text file containing the names of the packages you wish to remove, with each package name on a separate line.
creating list of packages in a text file
  1. Use the following command to uninstall all the packages listed in the text file:
sudo xargs apt remove < package_list.txt
  1. This command reads the package names from the package_list.txt file and uninstalls all the listed packages in a single batch operation.
uninstalling multiple packages at a time

How to Revert Package Uninstallations

Apt’s versioning feature comes to the rescue when you realize you need to bring back a previously uninstalled package. This functionality allows you to quickly and effortlessly rectify any unintended package removals and restore system stability. To do this:

  1. Use the apt policy command to view the available versions of a package:
apt policy package_name
  1. This command will display information about the specified package, including its installed version and available versions in the repositories.
listing available version of the package
  1. To reinstall a specific package version, use the install option followed by the package name and the desired version:
sudo apt install package_name=version
  1. This command allows you to install the specified version of the package. Replace package_name with the actual name of the package and version with the desired version number.
reverting the uninstallation of the package

5 Tips to Uninstall Packages With Apt Package Manager

Mastering the art of uninstalling packages with Apt Package Manager is essential for efficient Linux system maintenance. Apt, being a widely-used package manager, streamlines software management on various distributions. These five expert tips will help you navigate the process flawlessly and keep your system clean and optimized:

  • 🔍 Choose the Right Uninstall Command: Use apt remove to uninstall a package but keep its configuration files if you might reinstall it later. For a complete removal, use apt purge, which deletes the package and its configuration files, freeing up disk space and avoiding potential conflicts.
  • 🗂️ Batch Uninstall Multiple Packages: Save time by listing all the packages you want to uninstall in a text file. Use xargs to read the file and uninstall them all at once. This is especially useful for system cleanup or removing unwanted software quickly.
  • 🚫 Carefully Remove Configuration Files: When you use apt remove, configuration files remain on your system. If you want a clean uninstallation, manually delete these files using the dpkg command. This prevents potential conflicts if you reinstall the package later.
  • 🔄 Revert Package Uninstalls When Needed: If you accidentally remove a package, use apt policy to check available versions and reinstall it with apt install. This feature helps you quickly undo mistakes, especially with critical packages.
  • 🏆 Leverage Advanced Apt Features: Use apt-mark hold to protect important packages from updates or removals. Explore package pinning to prioritize specific package versions from certain repositories. These advanced features help maintain system stability and ensure compatibility with your needs.

Apt Delete Package: Summing Up

In this article, I’ve explored methods to uninstall packages using Apt, such as apt remove and apt purge, as well as batch uninstalling with xargs. Essential tips for managing packages include removing configuration files, reverting uninstalls, and leveraging advanced features like apt-mark hold.

If you want to explore more, I’ve got some great suggestions for you:

Frequently Asked Questions

What Happens If I Uninstall a Package Required by Other Installed Applications?

When you uninstall a package that serves as a dependency for other installed applications, it can lead to adverse consequences. The dependent applications may malfunction or fail to work altogether, resulting in errors and instability. Apt typically provides warnings about such dependencies before removal, giving you a chance to reconsider the action. It’s crucial to carefully review these warnings and ensure that removing the package won’t cause any critical issues for other software components on your system.

Can I Reinstall a Package With the Exact Same Configuration After Uninstallation?

Unfortunately, Apt does not automatically preserve the exact configuration settings of a package when you reinstall it. After uninstallation and reinstallation, the package typically returns to its default configuration state. If you had customized settings or preferences before uninstalling the package, you’ll need to manually restore them after the reinstallation. Keeping a backup of your configuration files before uninstalling a package can be helpful in such situations.

What Should I Do If I Accidentally Uninstall a Critical System Package?

If you accidentally uninstall a critical system package, don’t panic. First, try rebooting your system to see if it can recover. Sometimes, the package might get reinstalled during the boot process. If the issue persists, you can use a live USB or rescue disk to access your system and reinstall the missing packages. Alternatively, if you maintain regular system backups, you can restore your system to a previous state to recover the accidentally removed package and its dependencies.

How Do I Ensure That Specific Packages Won’t Be Updated or Removed During System Upgrades?

You can prevent specific packages from being updated or removed during system upgrades by utilizing the apt-mark hold feature. This command allows you to hold a package at its current version, ensuring that it remains unaffected during the upgrade process. To hold a package, use the command sudo apt-mark hold package_name. This feature is particularly useful for critical packages or software components that need to remain static to maintain system stability. By holding essential packages, you can confidently perform system upgrades without worrying about unintended changes to critical software components.



Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.



Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to List Docker Containers in Linux [3 Effective Methods]

Next Post

How to Install GNOME Disks Utility on Ubuntu and Configure It [3 Simple Methods]

Leave a Reply

Your email address will not be published. Required fields are marked *

Read next