Ubuntu – How to completely remove virtual packages

aptpackage-managementserver

It turns out that removing a virtual package with apt-get only remove the package itself, leaving behind the real packages that were installed by it

So how do you remove a virtual package, along with all the real packages that it installs?

Best Answer

Use apt-cache depends to find a list of packages that the virtual package "contains" and then remove all of those in order to remove the virtual package. For example:

$ sudo apt-cache depends mono-complete
mono-complete
  Depends: mono-runtime
  Depends: mono-runtime-sgen
  Depends: libmono-2.0-1
  Depends: libmono-profiler
  Depends: mono-utils
  Depends: mono-jay
  Depends: mono-devel
  Depends: mono-mcs
  Depends: mono-csharp-shell
  Depends: mono-4.0-gac
  Depends: mono-4.0-service
  Depends: monodoc-base
  Depends: monodoc-manual
  Depends: libmono-cil-dev
  Depends: ca-certificates-mono

Now all you have to do is sudo apt-get remove all of the packages listed after Depends: and once done, the virtual package mono-complete will be removed automagically.

Run sudo apt-cache depends command first to take a look at all the dependent packages, and then, if the list of packages looks to you that it is ok to be removed, you can use this to remove them all:

$ sudo apt-get remove `apt-cache depends mono-complete | grep Depends | cut -d : -f 2`

Once the job is done, you can check virtual package status with:

$ dpkg -l mono-complete

It should be marked as (n)ot installed.