Tips for maintaining Debian Linux

Some notes on maintaining Debian installation in a long run.

Finding installed "orphaned" or non-Debian packages

During the distribution evolution, packages come and go and sometimes you'll end up with some installed software that has disappeared from the official repositories. Or another option being that once you installed something from a 3rd party repository (for example PGDG for improved PostgreSQL packages) and have dropped these.

Easiest way (that I have found) for listing non-Debian packages:

apt list '?narrow(?installed, ?not(?origin(Debian)))'

Cleaning up cruft

As Debian packages usually have dependencies, package manager is able to differentiate between manually installed packages and their dependencies, and uses manual/auto terms for these.

This means that whenever installing package called app depending on two currently uninstalled dependencies lib1 and lib2, after installation system will contain 3 extra packages in two categories:

Once you decide to uninstall the app package, then package manager will also suggest removing lib1 and lib2 together with app, unless no other packages require these as dependencies or someone has meanwhile decided to manually reinstall lib1 or lib2 packages.

In order to handle the auto/manual list, Debian has apt-mark utility, allowing to list all the manually installed packages:

apt-mark showmanual

If output contains some packages that shouldn't be there (for example try apt-mark showmanual 'lib*'), these packages can be then reassigned into auto category:

apt-mark auto lib1
lib1 set to automatically installed.

Now when running apt-upgrade and no other packages require lib1 as a dependency, apt should suggest autoremoving it:

apt upgrade
The following packages were automatically installed and are no longer required:
  lib1
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Downgrading packages (after repository removal)

Some time ago, when I decided to drop usage of PGDG packages, I ran into issues where some of the non-Debian packages were newer than the official Debian packages with the same name. As these were also so-called "common" packages on which other already installed packages depended on, I had to make sure all these cross-requirements were installed in a single update transaction and I also had to specify a downgrade version:

apt install --reinstall postgresql-client-common=248 postgresql-common=248