How to delete orphaned packages - Pacman vs. Pamac

Hello,

I come from Manjaro and in Pamac there is the function under Installed → Orphaned. There you can have all orphaned packages listed with just one click.
I got to know the function when I had a problem with a system update. I don’t remember what it was, but some package was supposed to be updated and that didn’t work properly, instead causing the RAM to slowly fill up and the system then hang. As it turned out, the “faulty” package was no longer needed and was listed right there under Orphaned on Pamac.
If I had removed the package there before the system update, I would not have fallen into this trap in the first place.

Since then, I have always used Pamac in such a way that I usually checked for orphaned packages immediately after an update and then uninstalled them if necessary.
You read a lot of bad things about Pamac here, but I have to say that this function served me well for about 1.5 years and never led to an error.

Now I wanted to see what the alternative would be under Pacman in EndeavorOS.
I found the following two commands:

Find/List Orphaned Packages:
pacman -Qdt

Remove:
sudo pacman -Rsn $(pacman -Qdtq)

The latter command is also controversially discussed!
And, since I don’t want to destroy my system right away, I wanted to get to the bottom of the matter a little more carefully before I let the command become routine.

To do this, I simply empirically compared how Pacman vs. Pamac behaved in the VM.

First of all, here is the output of Pacman (it’s actually self-explanatory):

[john@john ~]$ pacman -Qdt
appstream-glib 0.8.2-3
asciidoc 10.2.0-3
boost 1.83.0-1
cmake 3.27.4-1
gendesk 1.0.9-3
go 2:1.21.0-1
go-tools 4:0.12.0-1
gobject-introspection 1.76.1-3
gtest 1.13.0-1
itstool 1:2.0.7-1
kjs 5.109.0-1
lua52 5.2.4-5
meson 1.2.1-1
python-docutils 1:0.20.1-1
vala 0.56.13-1
[john@john ~]$ sudo pacman -R $(pacman -Qdtq)
[sudo] Passwort für john:
Abhängigkeiten werden geprüft …

Paket (15)             Alte Version  Netto-Veränderung

appstream-glib         0.8.2-3               -3,74 MiB
asciidoc               10.2.0-3              -2,41 MiB
boost                  1.83.0-1            -178,93 MiB
cmake                  3.27.4-1             -71,14 MiB
gendesk                1.0.9-3               -6,40 MiB
go                     2:1.21.0-1          -201,62 MiB
go-tools               4:0.12.0-1           -87,53 MiB
gobject-introspection  1.76.1-3             -13,16 MiB
gtest                  1.13.0-1              -2,11 MiB
itstool                1:2.0.7-1             -0,09 MiB
kjs                    5.109.0-1             -1,53 MiB
lua52                  5.2.4-5               -0,92 MiB
meson                  1.2.1-1              -13,09 MiB
python-docutils        1:0.20.1-1            -5,72 MiB
vala                   0.56.13-1            -14,39 MiB

Gesamtgröße der entfernten Pakete:  602,77 MiB

:: Möchten Sie diese Pakete entfernen? [J/n] n
[john@john ~]$ sudo pacman -Rs $(pacman -Qdtq)
Abhängigkeiten werden geprüft …
:: gdk-pixbuf2 benötigt optional libheif: Load .heif, .heic, and .avif
:: glibc benötigt optional gd: for memusagestat
:: gperftools benötigt optional graphviz: pprof graph generation
:: groff benötigt optional netpbm: for use together with man -H command interaction in browsers
:: imagemagick benötigt optional libheif: HEIF support
:: libwbclient benötigt optional python-markdown: for samba-tool domain schemeupgrade
:: lv2 benötigt optional python-lxml: for lv2specgen.py
:: lv2 benötigt optional python-markdown: for lv2specgen.py
:: lv2 benötigt optional python-pygments: for lv2specgen.py
:: smbclient benötigt optional python-markdown: for samba-tool domain schemeupgrade

Paket (36)                Alte Version    Netto-Veränderung

cppdap                    1.58.0-1                -1,62 MiB
docbook-xml               4.5-9                   -1,96 MiB
docbook-xsl               1.79.2-7               -26,32 MiB
gd                        2.3.3-7                 -0,67 MiB
glib2-docs                2.76.5-1               -21,82 MiB
graphviz                  8.1.0-2                -11,28 MiB
gsfonts                   20200910-3              -3,11 MiB
gtk-doc                   1.33.2-3                -2,40 MiB
gts                       0.7.6.121130-2          -0,67 MiB
jsoncpp                   1.9.5-2                 -0,73 MiB
libheif                   1.16.2-1                -1,02 MiB
netpbm                    10.73.43-1              -6,78 MiB
ninja                     1.11.1-3                -0,35 MiB
python-lxml               4.9.2-3                 -5,08 MiB
python-mako               1.2.4-3                 -1,01 MiB
python-markdown           3.4.4-1                 -0,96 MiB
python-markupsafe         2.1.3-1                 -0,08 MiB
python-pygments           2.16.1-1               -13,80 MiB
python-tqdm               4.66.1-1                -0,65 MiB
python-typing_extensions  4.7.1-1                 -0,37 MiB
rhash                     1.4.3-1                 -0,32 MiB
appstream-glib            0.8.2-3                 -3,74 MiB
asciidoc                  10.2.0-3                -2,41 MiB
boost                     1.83.0-1              -178,93 MiB
cmake                     3.27.4-1               -71,14 MiB
gendesk                   1.0.9-3                 -6,40 MiB
go                        2:1.21.0-1            -201,62 MiB
go-tools                  4:0.12.0-1             -87,53 MiB
gobject-introspection     1.76.1-3               -13,16 MiB
gtest                     1.13.0-1                -2,11 MiB
itstool                   1:2.0.7-1               -0,09 MiB
kjs                       5.109.0-1               -1,53 MiB
lua52                     5.2.4-5                 -0,92 MiB
meson                     1.2.1-1                -13,09 MiB
python-docutils           1:0.20.1-1              -5,72 MiB
vala                      0.56.13-1              -14,39 MiB

Gesamtgröße der entfernten Pakete:  703,77 MiB

:: Möchten Sie diese Pakete entfernen? [J/n] n
[john@john ~]$ sudo pacman -Rsn $(pacman -Qdtq)
Abhängigkeiten werden geprüft …
:: gdk-pixbuf2 benötigt optional libheif: Load .heif, .heic, and .avif
:: glibc benötigt optional gd: for memusagestat
:: gperftools benötigt optional graphviz: pprof graph generation
:: groff benötigt optional netpbm: for use together with man -H command interaction in browsers
:: imagemagick benötigt optional libheif: HEIF support
:: libwbclient benötigt optional python-markdown: for samba-tool domain schemeupgrade
:: lv2 benötigt optional python-lxml: for lv2specgen.py
:: lv2 benötigt optional python-markdown: for lv2specgen.py
:: lv2 benötigt optional python-pygments: for lv2specgen.py
:: smbclient benötigt optional python-markdown: for samba-tool domain schemeupgrade

Paket (36)                Alte Version    Netto-Veränderung

cppdap                    1.58.0-1                -1,62 MiB
docbook-xml               4.5-9                   -1,96 MiB
docbook-xsl               1.79.2-7               -26,32 MiB
gd                        2.3.3-7                 -0,67 MiB
glib2-docs                2.76.5-1               -21,82 MiB
graphviz                  8.1.0-2                -11,28 MiB
gsfonts                   20200910-3              -3,11 MiB
gtk-doc                   1.33.2-3                -2,40 MiB
gts                       0.7.6.121130-2          -0,67 MiB
jsoncpp                   1.9.5-2                 -0,73 MiB
libheif                   1.16.2-1                -1,02 MiB
netpbm                    10.73.43-1              -6,78 MiB
ninja                     1.11.1-3                -0,35 MiB
python-lxml               4.9.2-3                 -5,08 MiB
python-mako               1.2.4-3                 -1,01 MiB
python-markdown           3.4.4-1                 -0,96 MiB
python-markupsafe         2.1.3-1                 -0,08 MiB
python-pygments           2.16.1-1               -13,80 MiB
python-tqdm               4.66.1-1                -0,65 MiB
python-typing_extensions  4.7.1-1                 -0,37 MiB
rhash                     1.4.3-1                 -0,32 MiB
appstream-glib            0.8.2-3                 -3,74 MiB
asciidoc                  10.2.0-3                -2,41 MiB
boost                     1.83.0-1              -178,93 MiB
cmake                     3.27.4-1               -71,14 MiB
gendesk                   1.0.9-3                 -6,40 MiB
go                        2:1.21.0-1            -201,62 MiB
go-tools                  4:0.12.0-1             -87,53 MiB
gobject-introspection     1.76.1-3               -13,16 MiB
gtest                     1.13.0-1                -2,11 MiB
itstool                   1:2.0.7-1               -0,09 MiB
kjs                       5.109.0-1               -1,53 MiB
lua52                     5.2.4-5                 -0,92 MiB
meson                     1.2.1-1                -13,09 MiB
python-docutils           1:0.20.1-1              -5,72 MiB
vala                      0.56.13-1              -14,39 MiB

Gesamtgröße der entfernten Pakete:  703,77 MiB

:: Möchten Sie diese Pakete entfernen? [J/n]

A sudo pacman -R $(pacman -Qdtq) only removes exactly the 15 orphaned packages found.
However, a sudo pacman -Rs $(pacman -Qdtq) and also a sudo pacman -Rsn $(pacman -Qdtq) both suddenly remove 36 packages!

In contrast, Pamac also finds exactly the same 15 orphaned packages (I saved myself a duplicate listing).

If I select all packages to remove and confirm, I get an intermediate query that suddenly says 27 packages to remove. I wrote these out here (Orphan is German and my orphan):

itstool
cmake
cppdap (Waise von: cmake)
rhash (Waise von: cmake)
jsoncpp (Waise von: cmake)
go
meson
python-tqdm (Waise von: meson)
python-typing_extensions (Waise von: meson)
ninja (Waise von: meson
appstream-glib
boost
gobject-introspection
python-mako (Waise von: gobject-introspection)
python-markupsafe (Waise von: gobject-introspection)
gtest
gendesk
asciidoc
go-tools
kjs
python-docutils
vala
gtk-doc (Waise von: vala)
glib2-docs (Waise von: vala)
docbook-xsl (Waise von:asciidoc)
docbook-xml (Waise von: asciidoc)
lua52

So apparently Pamac also removes dependencies that are no longer needed, but why does Pamac end up with 27 packages and Pacman with 36?
Or to put it another way, does anyone know what exactly Pamac is doing in the background, what command is being executed there?

PS: Sorry, my english is not the best!

After more than 3 years M… with Pamac, I can only say: Hands off Pamac!

1 Like

I would have to do more research on your exact situation but I suspect that pamac is actually doing the more correct thing here.

I talk about this a lot but there is something you need to be aware of when using pacman -Rs, it can remove optional dependencies of other packages.

When I remove orphans on my own system, I can pacman -R in a loop until there are no orphans left to avoid that situation.

3 Likes

Yes, that could be the difference!

I just compared it again in another VM (also with EndeavorOS ).
There the difference was 14 (Pamac) to 16 (Pacman) packages, and in detail were the two extra packages Pacman would have removed with the command sudo pacman -Rsn $(pacman -Qdtq) :

java-environment-common 3-5 0.00 MiB
jdk-openjdk 20.0.2.u9-3 -295.14 MiB

But I could remember these packages, which I had installed as optional dependencies with LibreOffice.

Pacman would have uninstalled me so just badass!

Good tip, thanks!

And that would also explain why you sometimes have to/can run Pamac multiple times in a row. Because after removing orphaned packages, it sometimes suddenly finds new orphaned packages again…

But apparently Pamac doesn’t just do a simple thing pacman -R $(pacman -Qdtq)
Because in my use case mentioned above, Pamac first finds 15 orphaned packages, but when I select all of them and click Remove, it suddenly writes me 27 packages (and not just the 15 that Pacman also used -R $(pacman -Qdtq ) would remove). So Pamac still has to do some other intermediate step!

As a compromise, one could perhaps also proceed in two ways: install and selectively uninstall via the console, remove orphaned packages via pamac.

No, because that would leave orphans behind in many cases. This is because when you remove the current orphans you often create new ones.

But you don’t know exactly which command Pamac executes, do you?

Because, as I said, apparently Pamac has done well for me at Manjaro for the last year and a half. There was never too much or too little removed.

If I knew the exact command, I’d like to run it in Pacman.

pamac has it’s own logic. It doesn’t use pacman commands.

Yes, it uses pamac command line.
But as far as I know, the syntax there is the same as pacman.
But even if not, there must be some command.

You can use

yay -Yc

or

paru -c
5 Likes

No, it doesn’t call commands, it interfaces directly with libalpm.

And that’s enough to find all the orphans?

Yes.

Hmm…
yay -Yc
seems very similar to the Pacman command sudo pacman -Rsn $(pacman -Qdtq) .

Just tested this in my two VMs, here is a comparison of how many packages would be removed:

VM1:
Pamac: 27
Pacman: 36
Yay: 36

VM2:
Pamac: 14
Pacman: 16
Yay: 17

The 17th package, which yay would also remove, is called ninja.
If I take a closer look it says:
Depends on: gcc-libs
Optional for: flutter
And just like with Pacman, the optional dependencies mentioned above (Java or jdk-openjdk) would also be removed.

there is a clear difference for me.

[pycrk@eno ~]$ yay -Yc
[pycrk@eno ~]$ pacman -Qtdq
lib32-attr
lib32-libgudev
lib32-libvpx
[pycrk@eno ~]$ yay -Qtdq
lib32-attr
lib32-libgudev
lib32-libvpx

It seems to really depend.

Here is my summary.

  • Both the wiki recommended pacman method and yay/paru remove optional dependencies in certain cases
  • yay/paru finds dependencies that pacman does not in some cases. For me, it found a loop of optional deps that pacman did not.
  • Pamac does a much better job of not removing optional dependencies

I will probably stick with my method of removing orphans in a loop. It works for me and doesn’t remove optional deps.

4 Likes

Would you be willing to share your script or command? I would be curious to try it out!

1 Like

It would be easy to put it in a script, however, I typically just do it manually. I don’t think I have ever had more than 3 iterations. I also remove orphans quite infrequently. If I did it more often, I would probably write a script or a one-liner for it.

1 Like

as far as the subject is concerned, I’m at a loss the more I deal with it and test it. we had this topic before. The problem is, you won’t find any really useful information about it.

Would you share this with us newbies, please?

I run sudo pacman -R $(aura -O) until I get an error that no targets were specified.

If you don’t use aura, you could just as easily run sudo pacman -R $(pacman -Qdtq)

It would be trivially easy to write a script like that automates that if you cared.

7 Likes