Debian

Uninstall Ubuntu and Debian Packages With apt-get and dpkg

We already saw how to create Debian packages. Now, we will see how to remove them. Removing packages in Debian or Ubuntu Linux from the console is very easy, your user must be in the sudoers or you will need root access.

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.

dpkg --list

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.

sudo apt-get --purge remove skypeforlinux

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:

sudo apt-get --purge remove skypeforlinux -y

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:

sudo apt-get purge skypeforlinux -y

If you want to keep the configuration files, run:

sudo apt-get remove skypeforlinux

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:

sudo dpkg --remove skypeforlinux

We also can use the -r parameter instead of remove, as shown below:
Note: Where “PackageName” is replaced by the package’s name.

sudo dpkg -r <PackageName>

Removing Broken Packages

n order to remove broken packages or packages which weren’t fully installed, we will run:

sudo apt-get clean && sudo apt-get autoremove
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 apt-get update
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:

sudo apt-get -u dist-upgrade

The previous command shows you held packages. If listed to remove packages, run:

apt-get remove -dry-run <packagename>

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.

sudo apt list

Removing packages with apt is the same as with apt-get, to remove a program binaries and configuration files run:

sudo apt purge skypeforlinux

You can use the command remove instead of purge to keep configuration files.

sudo apt remove skypeforlinux

Like with apt-get, you can add the -y option to prevent confirmation.

sudo apt remove skypeforlinux -y

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.

About the author

David Adams

David Adams is a System Admin and writer that is focused on open source technologies, security software, and computer systems.