An obsolete package is a package who is no longer provided by any of the APT repositories listed in /etc/apt/source.lists
(and /etc/apt/sources.list.d/
).
In this article, we will explain how to remove previously installed and obsolete packages on Ubuntu.
Why do obsolete packages stay in the system?
The following items give an idea about this:
- The upstream author stopped maintaining the software a long time ago, nobody else took over. The Ubuntu maintainer preferred to remove the package from Ubuntu. But the package is still installed on your system.
- The package had very few users. The Ubuntu QA team might have asked its removal.
- The latest version of the software might have been packaged under a new package name. Therefore, it remains in the system as the obsolete package.
Therefore, it is not a good idea to keep outdated packages on the system. They do not benefit from security updates and can cause problems during the upgrade if they depend on other packages that must be removed to complete the upgrade.
How to list obsolete packages?
Ubuntu also came with the APT 2.0, which allows the use of smarter patterns when listing the packages. All old packages are listed using "?obsolete
" or "~ O
" shortcut:
Usage with "~o
" :
foc@foc-ubuntu21:~$ apt list ~o
Listing... Done
anydesk/now 6.2.1 amd64 [installed,local]
zoom/now 5.12.6.173 amd64 [installed,local]
Usage with "?obsolete" :
foc@foc-ubuntu21:~$ apt list ?obsolete
Listing... Done
anydesk/now 6.2.1 amd64 [installed,local]
zoom/now 5.12.6.173 amd64 [installed,local]
The above 2 methods showed the packages that were not installed from ubuntu repository. In fact, the /etc/apt/source.lists file and /etc/apt/sources.list.d/ showed the packages that were not loaded from the repositories in the files under the directory.
You can also list all packages not provided by Ubuntu. For example:
foc@foc-ubuntu21:~$ apt list --installed "?not(?origin(ubuntu))"
Listing... Done
anydesk/now 6.2.1 amd64 [installed,local]
teamviewer/stable,now 15.36.6 amd64 [installed,upgradable to: 15.36.8]
zoom/now 5.12.6.173 amd64 [installed,local]
The TeamViewer package was also listed. Because this package was installed from its own repository, not from ubuntu repository:
foc@foc-ubuntu21:~$ ls /etc/apt/sources.list.d/
teamviewer.list
How to remove obsolete packages?
We have listed the packages that are not installed and obsolete from Ubuntu Repository. Let's delete them now.
With APT's "Remove" and "Purge" commands, you can delete the packages one by one:
foc@foc-ubuntu21:~$ sudo apt remove anydesk -y
or
foc@foc-ubuntu21:~$ sudo apt purge anydesk -y
If we want to delete these packages collectively:
foc@foc-ubuntu21:~$ sudo apt remove ~o
[sudo] password for foc:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libegl1-mesa libgtkglext1 libpangox-1.0-0 libxcb-xtest0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
anydesk zoom
0 upgraded, 0 newly installed, 2 to remove and 249 not upgraded.
After this operation, 539 MB disk space will be freed.
Do you want to continue? [Y/n]
or
foc@foc-ubuntu21:~$ sudo apt remove ?obsolete
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
libegl1-mesa libgtkglext1 libpangox-1.0-0 libxcb-xtest0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
anydesk zoom
0 upgraded, 0 newly installed, 2 to remove and 249 not upgraded.
After this operation, 539 MB disk space will be freed.
Do you want to continue? [Y/n]
All packages are deleted with your approval.
Finally, to delete those who do not have original ubuntu packages:
foc@foc-ubuntu21:~$ sudo apt remove "?not(?origin(ubuntu))"
The following packages were automatically installed and are no longer required:
libegl1-mesa libgtkglext1 libminizip1 libpangox-1.0-0 libxcb-xinerama0
libxcb-xtest0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
anydesk teamviewer zoom
0 upgraded, 0 newly installed, 3 to remove and 248 not upgraded.
After this operation, 809 MB disk space will be freed.
Do you want to continue? [Y/n]
Packages are removed together with their addictions.
Summary
In this article, we explained how to list and delete the Obsolete Packages, which is installed in the system.
In the system, there may be packages dependent on these packages. Therefore, it can be useful to delete one by one. Be careful to delete the package.
Further Reading
Is it recommended to remove obsolete packages after a dist upgrade?