Get a List of Installed Packages: dpkg –list
The command dpkg –list will show you a list of installed packages. You can use this command to get a list of names of installed programs to remove later. Of course, you don’t need to use this command if you already know the name of the program to remove.
By scrolling down, you can see all installed packages. As you can see in the screenshot below, one of the installed packages in my device is skypeforlinux, the program I will use in these tutorial examples:
Removing Packages Using apt-get:
When using apt-get, the correct method to remove packages through the console is shown below. The parameter “–remove” will remove installation files while keeping configuration data, by adding “–purge” we instruct apt-get to remove configuration files, too.
When asked for confirmation, press Y to finish the removal procedure. You can also skip the confirmation request by adding -y when executing the command as shown in the image below:
You can also run apt-get purge without the remove parameter, as shown in the example below. This will remove both program binaries and configuration files.
Or you can simply remove binaries keeping configuration files by running:
If you want to keep the configuration files, run:
Note: you can add the -y option to avoid confirmation.
Removing Packages Using dpkg:
We can remove packages replacing the command apt-get with dpkg like in the following example:
We also can use the -r parameter instead of remove, as shown below:
Note: Where “PackageName” is replaced by the package’s name.
Removing Broken Packages
n order to remove broken packages or packages which weren’t fully installed, we will run:
sudo apt-get -f install
dpkg --configure -a
Where:
- clean: Removes cache of programs older than the installed.
- autoremove: Removes unnecessary files, like dependencies which are no longer needed.
- -f / –fix-broken install: Fix broken dependencies and correct possible package corruption problems. We will delve in this option later.
Troubleshooting
For different reasons, a package’s removal, or a package’s installation may return errors. Most common causes for such errors are old programs, partially installed packages, corrupted packages, and outdated repositories at etc/apt/sources.list, etc.
The following commands and their order are basic to solve initial problems in the packages manager. If you are experiencing problems installing or uninstalling software on Ubuntu or other Debian-based Linux distributions, run the following commands:
sudo dpkg --configure -a
sudo apt-get -f install
sudo apt-get clean
Where:
- apt-get update: Updates the packages’ list in the repositories.
- dpkg –configure -a: This command checks for dependency problems to fix.
- apt-get -f install: Another command to fix dependency problems.
- apt-get autoclean: Clean unnecessary dependencies.
Check If Packages Are Being Held by the Packages Manager
To check if the installer holds packages pending installation run:
The previous command shows you held packages. If listed to remove packages, run:
Uninstalling Packages Using apt:
While many users believe the apt command is a way to invoke apt-get, both commands have differences. In most cases, you can use apt as apt-get, keeping the same options. In a few cases, the options are implemented in a different way. For example, you can use the apt command to list all packages as we previously did with the dpkg command.
Removing packages with apt is the same as with apt-get, to remove a program binaries and configuration files run:
You can use the command remove instead of purge to keep configuration files.
Like with apt-get, you can add the -y option to prevent confirmation.
Conclusion:
As you can see Debian-based Linux distributions offer a variety of ways to remove packages. Ubuntu also includes, by default, the aptitude packages manager, which wasn’t explained in this tutorial, but you can read about it at https://linuxhint.com/debian_package_managers/.
Commands explained in this tutorial are basic Debian commands any user-level must learn.
I hope this tutorial on uninstalling packages was helpful. Keep following Linux Hint for more Linux tips and tutorials.