Cleaning up OS after many updates and upgrades - orphaned packages etc

I am checking my system in a quiet moment and working with the guidance from the Advanced administration: Managing software with command line tools chapter 2.1.4.4 to list orphaned packages. It says:
With this list, you can decide if a package is still needed or can be removed safely.

Since I have quite a number of these listed I would like to understand more about finding out if these are needed. Alternatively is there a command which will clean out what is no longer required when or after updates are done?
I have a similar question concerning services.

Only you know how you use the system and for what purposes.

“Orphaned” just means that (the exact versions of) these packages are not available from any configured repository. It does not imply anything about whether you still need these packages or not.

Yet another wish for a mind reading computer.

I was thinking along the lines of what is the openSUSE equivalent of :-

apt-get autoremove

And what is that? And what does it do?

There is no direct equivalent in zypper. The closest is zypper rm --clean-deps, but it can only be used when explicitly removing some package.

It removes packages that are marked as “automatic installed dependency” (i.e. not on explicit user request) but are no more required by any currently installed package. So yes, technically they are unneeded. The corner case is if something installed outside of package management system (self-compiled or downloaded binary) still needs them.

At last! Many thanks, that explains why there is no simple answer which I understand. Housekeeping is often hard work and I am trying to learn and understand the tools. No Dyson here then, only a dust pan and brush!

On checking some of my orphaned packages I see they are all sourced from vendor SUSE LLChttps://www.suse.com/ (installed)

Since this is not a repo site which I expected to see, how are they sourced by my system, where are they from and how can I find out what uses them. It seems likely I can delete them. Is that a reasonable decision?

Just try to remove them and you will see.

you can also use:
rpm -q --whatrequires PACKAGENAME
to see, which package requires PACKAGENAME

rpm -q --whatrequires libgimp-2_0-0
gimp-devel-2.10.34-lp155.6.3.x86_64
gimp-2.10.34-lp155.6.3.x86_64

OK that helps and now I have no orphaned packages. Thanks for the help.

I have been able to clean up one system and have started on the next. I am finding a similar bunch of over 50 orphaned packages. At a glance they are the same set as I have just removed on the first machine.

Assuming these are all not required, is there a method for deleting these with one command?

Well,

zypper rm ... ... ...

takes multiple ‘capabilities’ (packages in this case). Thus yes.

I would gather them in a file (by re-directing the output of a command that lists them) and then use the editor of my choice to strip off all superfluous text and then create one command out of them.

Hi and yes but in fact by the time I had edited the unwanted text it has proven quicker just to remove them one at a time with the list in one console and another for entry.

All done but I think you will appreciate my point re the apt-get autoremove because this reminder is given when updating and at the most appropriate time to clean up. I wonder why openSUSE have not done the same thing.

It is always a trade of between doing the dumb typing or making some automation. What is more time consuming? The boundary between two is very dependent upon one’s skills. Can you create a quick script or not? Can you type error free with some speed?

One thing is for sure. In many cases one makes the wrong choice. :wink:

As I do not know the apt, I have not much comment on that. But, reading @arvidjaar 's short explanation, it may not be what you need. In any case it is not the orphaned packages it works on.

But I can live with YaST and zypper just fine. I assume that usng YaST and looking for packages shown in red and then clicking before them to remove is also rather easy. Choice enough.

To list all packages explicitly installed and not required as dependencies ( like “pacman -Qet”):
https://wiki.archlinux.org/title/Pacman

#!/bin/bash
################################################################################
# /usr/local/sbin/rpmDependencies.sh
#
# Alle sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepakete (RPM)
# suchen
#
# GrandDixence, 05.04.2023
#
################################################################################

echo "-------------------------------------------------------------------------"
echo "Start von rpmDependencies.sh"
echo "-------------------------------------------------------------------------"

echo " "
echo "Variablen deklarieren..."
rpmListe=/tmp/rpmImstalliertListe.txt
noDependenciesListe=/tmp/noDependenciesListe.txt

echo " "
echo "Liste aller installierten Softwarepakete erstellen..."
/usr/bin/rpm -qa|/usr/bin/sort > ${rpmListe}

echo " "
echo "Allenfalls schon vorhandene Liste der der sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepakete löschen..."
if [ -f ${noDependenciesListe} ];
then
  /usr/bin/rm ${noDependenciesListe}
fi;

echo " "
echo "Liste aller sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepaket erstellen..."

while IFS= read -r softwarePaket
do
  rpmAusgabe=$(/usr/bin/rpm --erase --test ${softwarePaket} 2>&1)

  if echo ${rpmAusgabe} | grep -v -q "Failed dependencies"; 
  then
    kurzName=`/usr/bin/rpm -q --queryformat "%{NAME}" ${softwarePaket}`;   
    echo "${kurzName}" >> ${noDependenciesListe};
    echo "${kurzName}";  
  fi;
done < ${rpmListe}

echo " "
echo "Liste erfolgreich erstellt."
echo "Die Liste wurde unter:"
echo " "
echo "${noDependenciesListe}"
echo " "
echo "abgelegt."

echo " "
echo "Ende von rpmDependencies.sh"
echo "-------------------------------------------------------------------------"
exit 0
# ls -alh /usr/local/sbin/rpmDependencies.sh
-rwx------ 1 root root 1.7K 23. Jul 22:43 /usr/local/sbin/rpmDependencies.sh

# /usr/local/sbin/rpmDependencies.sh
# more /tmp/noDependenciesListe.txt

And for Ubuntu 20.04 LTS:

#!/bin/bash
################################################################################
# /usr/local/sbin/debDependencies.sh
#
# Alle sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepakete (DEB)
# suchen
#
# GrandDixence, 10.04.2023
#
################################################################################


echo "-------------------------------------------------------------------------"
echo "Start von debDependencies.sh"
echo "-------------------------------------------------------------------------"

echo " "
echo "Variablen deklarieren..."
debListe=/tmp/debImstalliertListe.txt
noDependenciesListe=/tmp/noDependenciesListe.txt

echo " "
echo "Liste aller installierten Softwarepakete erstellen..."
/usr/bin/dpkg-query --show --showformat='${Package}\n' > ${debListe}

echo " "
echo "Allenfalls schon vorhandene Liste der der sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepakete löschen..."
if [ -f ${noDependenciesListe} ];
then
  /usr/bin/rm ${noDependenciesListe}
fi;

echo " "
echo "Liste aller sich zuoberst im Abhängigkeitsbaum befindlichen Softwarepaket erstellen..."

while IFS= read -r softwarePaket
do
  aptAusgabe=$(/usr/bin/apt-cache rdepends ${softwarePaket} --installed --important 2>&1 | /usr/bin/grep -c "")

  if echo ${aptAusgabe} | /usr/bin/grep -q "2";
  then
    echo "${softwarePaket}" >> ${noDependenciesListe};
    echo "${softwarePaket}";
  fi;
done < ${debListe}

echo " "
echo "Liste erfolgreich erstellt."
echo "Die Liste wurde unter:"
echo " "
echo "${noDependenciesListe}"
echo " "
echo "abgelegt."

echo " "
echo "Ende von debDependencies.sh"
echo "-------------------------------------------------------------------------"
exit 0

What exactly is “explicitly installed package”?

A package that was not installed as a dependency of another package.

Your script does not list such packages. RPM does not know whether package was installed as dependency or not. Your script lists packages that are not required by other packages. Whether packages in this list were installed as dependency or on explicit user request is not known.