Uninstalling Packages With Apt Package Manager

Uninstalling Packages With Apt Package Manager

If you’re running a Debian or Ubuntu-based distribution and want to get rid of a package, you can do so in several methods using the apt package manager. However, knowing when to use each technique and what sets them apart can be difficult. We will explore the different options for finding and removing packages. We’ll break down when you should use the “purge” instruction versus the “remove” one. More than that, we will provide you with some helpful instructions to run after an uninstall to ensure a clutter-free operating environment. When you’re done reading this article, you’ll have a firm grasp on how to uninstall software packages quickly and easily.

Find The Package You Want To Uninstall

First things first, we need to find the packages in Ubuntu which we want to uninstall. We can very easily locate our package’s exact name with the following :

dpkg --list | grep <package-name>

This helps us to locate the exact package which we would require for the future steps. Once, we have located our desired package, we can move onto the next step.

Obtaining a list of installed packages

1. Using dpkg

Obtaining a list of installed packages in Linux is beneficial for various purposes, including tracking installed software and creating a backup of the system. Thankfully, there are several methods to complete this task.

The dpkg command, which is a package manager for Debian-based systems, is a common method. By executing the following command in the terminal, a catalog of all installed packages can be obtained:

dpkg --list

This command outputs an extensive list of all installed packages, including the package name, version, and a brief description of each package.

2. Using apt

Using the apt command, which is a package manager constructed on top of dpkg, is another useful method. Using apt, we can obtain a list of all installed applications by entering the following command in the terminal:

apt list --installed

This command provides a complete detail of installed packages, including the package name and version number.

If you are still confused on which package manager to use, here’s an amazing article that compares apt vs dpkg.

Uninstalling Packages With Apt

When talking about uninstalling packages using apt package manager on an Ubuntu System, we have the following two options :

  • sudo apt remove
  • sudo apt purge

1. Using apt remove

If you want to remove the packages, then you can do that by typing:

sudo apt remove <package-name>

You can also remove multiple packages by giving spaces after a package name.

2. Using apt purge

We can very easily remove a package with the ‘purge’ command as such :

sudo apt purge <package-name>

What’s the difference between ‘remove‘ and ‘purge‘ ?

So the begging question here is ‘remove‘ and ‘purge‘ and when to use what?

The primary difference between ‘remove’ and ‘purge’ is that ‘remove’ only removes the package, leaving any configuration files untouched. Meanwhile, ‘purge‘ removes the package and all configuration files OUTSIDE THE HOME DIRECTORY.

A Fun Little Secret

Contrary to their primary function, both ‘purge‘ and ‘remove‘ can be used to INSTALL specified packages. This can be achieved by appending a ‘+‘ at the end of the package name, as such:

sudo apt <remove/purge> <package-name>+

Post-Uninstall Clean-Up

At this point, we have successfully removed/purged our package. Now, we can run some commands to perform post-removal cleanup out of good practice, which will remove configurations and any remaining files left on the system.

We can clear the cache of the old/outdated packages with :

sudo apt clean

You can also altogether remove any orphaned packages and dependencies from your system after a clean-up by running the autoremove command:

sudo apt autoremove

Finally, any failed/broken installs can be fixed with this command :

$ sudo apt -f install

Conclusion

Finally, removing software from a Linux machine is a breeze with the apt package manager. First, we can use the dpkg command to find the package we wish to remove. The apt program can then be used to uninstall or clean the package. The main distinction between the two is that remove does not delete setup files, whereas purge does. Furthermore, by adding a + to the package name, either command can be used to install it. Finally, it’s recommended that you clear the cache, remove any unused packages, and repair any broken installations using apt after uninstalling packages.

Package Management from the command line is one of the first things you should learn about any Linux environment, and hopefully, this article helped you learn to uninstall packages from your distribution.

References

If you want to learn more on apt, here’s Ubuntu’s official documentation to get you going.

How do I uninstall a package using the Apt package manager?

You can use the “apt-get remove” command followed by the package’s name to uninstall it from your system.

What is the difference between “apt-get remove” and “apt-get purge” commands?

“apt-get remove” removes the package but leaves its configuration files on your system, while “apt-get purge” removes the package and deletes its configuration files.

Can I use the Ubuntu Software Center to uninstall packages?

Yes, you can use the Ubuntu Software Center, a Linux distribution, to uninstall software packages from your Ubuntu system.

What should I do if the package I want to uninstall has dependencies?

You can use the “apt-get remove” command, and if there are dependency issues, apt will prompt you to confirm the removal of the package along with its dependencies.

Is it possible to manually remove a package from the system?

Yes, you can manually remove a package by deleting its files and dependencies, but it is recommended to use the package manager to ensure proper removal and avoid potential issues.

How can I uninstall an application from the command line?

You can uninstall an application from the command line using the “apt remove” command followed by the package’s name.

What are the consequences of uninstalling a package from my Linux system?

Uninstalling a package will remove the files associated with that package from your system, freeing up disk space and potentially resolving any conflicts or issues related to that package.

Can I reinstall a package after uninstalling it?

Yes, you can reinstall a package using the “apt-get install” command followed by the name of the package after uninstalling it from your system.