Ubuntu – How to tell whether a package was installed by dpkg or apt


I want to remove the package, but I forgot how I installed it through dpkg or apt-get

I try to check through dpkg-query -list | grep myPackage and apt list --installed | grep myPackage, but myPackage was shown on both.

so how can I tell whether the package was installed by dpkg or apt ?

In order to do the correct uninstall command, like: apt-get remove or dpkg -r

Best Answer

  1. Compare the log of /var/log/apt/term.log, which is the log file generated by apt and /var/log/dpkg.log, which is the log file generated by dpkg. If you note a package name which can be found in /var/log/dpkg.log but not in /var/log/apt/term.log, it is very likely that you installed the package by dpkg that time.

  2. Please remember apt is a frontend for dpkg. Thus, it is recommended to remove any package by apt rather than dpkg, because apt will handle the dependency to remove those packages which will not be used by any other packages (, or mark them as "not use anymore" to let you remove them later. It depends on the exact apt options you actually use). However, it is no harm to you to remove your package by dpkg if you want. You will just likely leave many packages that you won't use anymore.