How to identify snaps on my system I no longer need?

OS: Ubuntu 20.04

The following is the output of snap list on a new install of Ubuntu 20.04:

$ snap list
Name                             Version             Rev   Tracking         Publisher   Notes
core18                           20200311            1705  latest/stable    canonical✓  base
gnome-3-34-1804                  0+git.2c86692       27    latest/stable/…  canonical✓  -
gtk-common-themes                0.1-36-gc75f853     1506  latest/stable/…  canonical✓  -
snap-store                       3.36.0-74-ga164ec9  433   latest/stable/…  canonical✓  -
snapd                            2.44.3              7264  latest/stable    canonical✓  snapd
$

And this is what I see after installing a variety of snaps (and removing some):

$ snap list
Name                             Version                     Rev   Tracking         Publisher   Notes
core                             16-2.44.3                   9066  latest/stable    canonical✔  core
core18 •                         20200427                    1754  latest/stable    canonical✔  base
firefox *                        77.0b2-1                    358   latest/beta      mozilla✔    -
gnome-3-28-1804                  3.28.0-16-g27c9498.27c9498  116   latest/stable    canonical✔  -
gnome-3-34-1804 •                0+git.2c86692               27    latest/stable/…  canonical✔  -
gnome-system-monitor *           3.32.0-27-g32ed970e06       135   latest/stable    canonical✔  -
gtk-common-themes •              0.1-36-gc75f853             1506  latest/stable/…  canonical✔  -
kanagram *                       20.04.0                     51    latest/stable    kde✔        -
kcolorchooser *                  20.04.0                     57    latest/stable    kde✔        -
kde-frameworks-5                 5.47.0                      27    latest/stable    kde✔        -
kde-frameworks-5-core18          5.61.0                      32    latest/stable    kde✔        -
kde-frameworks-5-qt-5-14-core18  5.68.0                      4     latest/stable    kde✔        -
kolourpaint *                    20.04.0                     56    latest/stable    kde✔        -
ksnip *                          1.7.0                       46    latest/edge      dporobic    -
okular *                         20.04.0                     98    latest/stable    kde✔        -
snap-store •                     3.36.0-74-ga164ec9          433   latest/stable/…  canonical✔  -
snapd •                          2.44.3                      7264  latest/stable    canonical✔  snapd
$

For ease of discussion, let's call

  • the five original snaps (tagged with next to their names) "system snaps"
  • the snaps I knowingly installed (tagged with * next to their names) "primary snaps"
  • and the other snaps "supporting snaps"
    • core
    • gnome-3-28-1804
    • kde-frameworks-5
    • kde-frameworks-5-core18
    • kde-frameworks-5-qt-5-14-core18

Given that a snap and a minimum of two revisions are stored by the system, and that some supporting snaps can be a couple of hundred MB (ls -lh /var/lib/snapd/snaps), it would be worth knowing which secondary snaps can be removed if the primary snap has been already removed.

But how does one "map" the supporting snaps to the primary snaps?

In my case, I can run snap connections okular to intuit that kde-frameworks-5-qt-5-14-core18 was installed as a consequence of sudo snap install okular.

But snap connections … works only if the relevant snap is still installed. I had installed but then removed falkon, featherpad, kcalc, konversation, palapeli, and the stable version of ksnip.

Is there a log file related to installing and removing snaps akin to /var/log/dpkg.log or /var/log/apt/history.log?

If not, how else is one to know if a "supporting" snap is still required?


A related, but unanswered, question is here: How can I list manually installed snaps and remove no longer needed automatically installed ones?


Solution 1:

Examining the snap.yaml files of all installed snaps may help us to know which "supporting" snaps are needed. Not listed "supporting" snaps can be removed.

Example:

~$ grep "default-provider:" /snap/*/*/meta/snap.yaml
/snap/snap-store/415/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/415/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/snap-store/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/132/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gnome-3-28-1804
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
/snap/wire/current/meta/snap.yaml:    default-provider: gtk-common-themes
~$ grep "base:" /snap/*/*/meta/snap.yaml
/snap/gnome-3-28-1804/116/meta/snap.yaml:base: core18
/snap/gnome-3-28-1804/current/meta/snap.yaml:base: core18
/snap/gtk-common-themes/1506/meta/snap.yaml:base: core18
/snap/gtk-common-themes/current/meta/snap.yaml:base: core18
/snap/snap-store/415/meta/snap.yaml:base: core18
/snap/snap-store/current/meta/snap.yaml:base: core18
/snap/wire/132/meta/snap.yaml:base: core18
/snap/wire/current/meta/snap.yaml:base: core18