Remove a package without its dependencies in Ubuntu

We can remove packages installed in Ubuntu either through apt or dpkg command-line utility. Although removing a package in Ubuntu is fairly simple through apt/dpkg command-line utilities. But, there are other packages which depend on the package we would want to uninstall. We call these other package – dependencies. So, if we uninstall a package then its dependencies may also get uninstalled along with it. Consider a scenario, wherein hundreds of other packages installed also need these dependencies and uninstalling these dependencies would leave our system in broken state. Therefore, in this article we would discuss how to remove a package without removing its dependencies in Ubuntu distribution.

Note: Following operations would require you to have superuser privileges. In case you don’t have one, then contact your System Administrator for assistance. Also, we would like to mention it beforehand that uninstalling a package without removing its dependencies must be considered on a case-by-case basis. We will see how it can affect your system with the help of an example later in the article.

Remove a package without removing its dependencies

We would use the dpkg command-line utility to remove a package while keeping its dependencies installed. Hence, run the following in terminal –

sudo dpkg -r --force-depends <package_name>

To completely remove the package, including configuration files, use purge (-P) option. This could be done through –

sudo dpkg -P --force-depends <package_name>

Now, we will discuss the worst-case scenario wherein you would want to remove Python3 package through Advanced Package Tool (APT). Since, the package is required by numerous other critical packages installed in our system. Thus, removing the package would render our system in an unusable state.

But, if you tried to remove the package through following command –

sudo dpkg -r --force-depends python3

Output –

dpkg: python3: dependency problems, but removing anyway as you requested:

Then, it will remove the package without removing the dependencies. And, things will be fine till you want to upgrade/install any other package.

So, next time you would want to install/upgrade a package it will throw an error –

E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Therefore, you need to fix the broken packages first i.e. python3. This could be fix through –

sudo apt install -f

The above command would fetch and install the python3 package again. And, then you are allowed to do further operations.

Why this happened?

There are so many packages which depend on python3 package. Even if we remove just one package and keep its dependencies installed. It just won’t work.

In conclusion, as we discussed at the beginning of the article. We need to remove the packages selectively. Since, dependencies is just a term in reference to the installed package. Otherwise, a dependency itself is a package. So, consider removing a package/dependency on a case-by-case basis.

Similar Posts