Uninstall Packages With Apt Package Manager[2 Proven Methods]

Written by

Reviewed by

Last updated: July 26, 2023

Expert verified

SVG Image


To uninstall packages 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.

To revert package uninstallations, use Apt’s versioning feature by checking available versions with apt policy and reinstalling the desired version using sudo apt install package_name=version. Follow these expert tips for efficient package management: choose the right uninstall command (apt remove or apt purge), batch uninstall with a text file and xargs, manage configuration files, and leverage advanced features like apt-mark hold and package pinning for precise system optimization.

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

In Linux, package management plays a pivotal role in maintaining a well-organized and efficient system. Apt, short for Advanced Package Tool, is a powerful package manager that simplifies the installation, removal, and management of software packages on various Linux distributions. Uninstalling packages with Apt is a crucial skill that empowers you to maintain a clean and optimized system effortlessly. In this article, I’ll explore different methods to uninstall packages with apt package manager, including how to remove single and multiple packages, handle configuration files and dependencies, and even revert package uninstalls. I will also discuss how to revert package installation and five tips to master the art of uninstalling using the apt package manager.

How to Uninstall Packages With Apt Package Manager

To uninstall packages with Apt Package Manager, you have two methods at your disposal. Firstly, for removing single packages, it’s a straightforward process – use apt remove to retain configuration files or apt purge for a clean removal. Secondly, to efficiently uninstall multiple packages simultaneously, create a text file with package names and utilize sudo xargs apt remove < package_list.txt

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:
<strong>apt show package_name</strong>
  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:
<strong>sudo apt remove package_name</strong>
  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:
<strong>sudo apt purge package_name</strong>
  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:
<strong>sudo apt autoremove</strong>
  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:
<strong>sudo xargs apt remove < package_list.txt</strong>
  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:
<strong>apt policy package_name</strong>
  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:
<strong>sudo apt install package_name=version</strong>
  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: When removing packages with Apt, it’s crucial to select the appropriate command based on your requirements. Use apt remove to uninstall a package while retaining its configuration files. This option is ideal when you may want to reinstall the package later, preserving any custom settings. On the other hand, if you want a complete removal without leaving behind any traces, apt purge is the way to go. It deletes not only the package but also its configuration files, freeing up disk space and avoiding potential conflicts in the future.
  • 🗂️ Batch Uninstall Multiple Packages: Handling multiple package removals can be time-consuming. Streamline the process by preparing a text file listing all the packages you wish to uninstall. This method is particularly useful when cleaning up a system or removing software you no longer need. To perform a batch uninstallation, execute a single command using xargs, which reads the package names from the text file and uninstalls them all at once. This time-saving tip allows you to efficiently manage your software packages without manual intervention.
  • 🚫 Carefully Remove Configuration Files: When uninstalling packages with apt remove, configuration files may remain on your system. This can be beneficial if you plan to reinstall the package in the future, as your custom configurations will still be intact. However, if you want to ensure a clean uninstallation, manually delete these files using the dpkg command. By identifying and removing the configuration files left behind after uninstallation, you can avoid potential conflicts or issues when reinstalling the package later on.
  • 🔄Revert Package Uninstalls When Needed: Mistakes happen, but with Apt’s versioning feature, you can easily rectify them. If you accidentally remove a package, use apt policy to check available versions and then reinstall the desired version using apt install. This tip ensures you can effortlessly revert package uninstalls without hassle. This feature is especially valuable when dealing with critical packages or system utilities, as it allows you to quickly roll back changes and maintain system stability.
  • 🏆 Leverage Advanced Apt Features: Take your package management to the next level by using advanced Apt features. For instance, you can employ apt-mark hold to protect critical packages from updates or removals during system upgrades. This prevents unintentional disruptions to essential software components and ensures the stability of your system during major updates. Additionally, explore package pinning with preferences files to prioritize specific package versions from designated repositories. This powerful technique allows you to tailor your system precisely to your needs and maintain compatibility with specific software versions.

In Conclusion

I hope this guide has provided you with valuable insights to uninstall packages with Apt Package Manager. By mastering the various methods and implementing the expert tips shared here, you can effortlessly declutter your Linux system, optimize its performance, and ensure a smooth package management experience. I have also included the methods to revert package uninstallation.

As you continue your journey of Linux and package management, I encourage you to explore other essential topics to deepen your knowledge. Discover more about system updates, significance of keeping your software up-to-date, and best practices for package installations. Furthermore, explore the vast world of Linux distributions, where you’ll find unique features, package managers, and communities that cater to specific preferences and needs. Keep expanding your expertise, and you’ll unlock the full potential of your Linux system.

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 [5 Effective Methods]

Next Post

How to Install GNOME Disks Utility on Ubuntu and Configure It [5 Simple Steps]

Leave a Reply

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

Read next