15

I have installed a few snap packages (snap install …). I can use snap list to list them. However I can not tell which are manually installed, and which were installed because other packages depend on them (auto in apt). I want to remove automatically installed packages (apt autoremove in apt), (docker system prune in docker).

5 Answers5

6

snap connections | grep XYZ where XYZ is the package whose dependencies you want to check.

For instance, I have a bunch of Gnome versions in the /snap directory. I don't know which to keep and which to get rid of. So on a whim, I uninstalled the "older" versions. Then it turns out some of the programs don't start anymore because they depended on the removed Gnome versions.

user@~ $simplenote 
ERROR: not connected to the gnome-3-28-1804 content interface.

This is a bad way of knowing that you removed something needed by other apps.

When I do snap connections | grep gnome, the output includes these lines:

user@~ $snap connections | grep gnome

content[gnome-3-38-2004] firefox:gnome-3-38-2004 gnome-3-38-2004:gnome-3-38-2004 - content[gnome-3-28-1804] simplenote:gnome-3-28-1804 gnome-3-28-1804:gnome-3-28-1804 -

This indicates the Gnome 3.28 and 3.38 versions are still being used by some programs and should not be removed.

ahron
  • 261
2

As far as I can tell, there is no prune/auto-remove feature at this time, but you can give a shot to

snap connections

It will list the connections that various snaps provide and have to each other and the system, so you can try figuring out which ones are not connected in any meaningful way to anything you actually need, and remove them manually.

You can inspect the connections of a specific snap by running snap connections <snap>, e.g.:

$ snap connections gnome-3-38-2004
Interface                 Plug                                       Slot                             Notes
content[gnome-3-38-2004]  firefox:gnome-3-38-2004                    gnome-3-38-2004:gnome-3-38-2004  -
content[gnome-3-38-2004]  gimp:gnome-3-38-2004                       gnome-3-38-2004:gnome-3-38-2004  -
content[gnome-3-38-2004]  snap-store:gnome-3-38-2004                 gnome-3-38-2004:gnome-3-38-2004  -
content[gnome-3-38-2004]  snapd-desktop-integration:gnome-3-38-2004  gnome-3-38-2004:gnome-3-38-2004  -

Keep in mind that the connections listing does not include the relationships of snaps that are the bases for other snaps (such as bare and all core snaps, i.e. core18, core20 etc.).

Kudos to this answer for pointing me in the right direction.

antichris
  • 215
2

I could do a script to show unconnected snaps:

show-unconnected-snaps

#!/bin/bash

list_connected_snaps_sorted() { snap connections
| tail -n +2
| awk '{print $1}'
| sort
| uniq }

list_all_snaps_sorted() { snap list
| tail -n +2
| awk '{print $1}'
| sort

}

echo "Unconneted snaps:" ( diff -U0 -u
<(list_connected_snaps_sorted)
<(list_all_snaps_sorted)
)
| grep '^+'
| tail -n +2
| cut -c2-

hope it helps

2

An update to the answer from @felipe-alcacibar above - sorry Felipe, but I don't have the reputation points to just comment.

The script actually misses connected snaps, as those are presented as, e.g., content[gnome-3-34-1804].

An updated script would need for list_connected_snaps_sorted() to look like the following, BUT PLEASE READ FURTHER:

list_connected_snaps_sorted() {
  snap connections \
    | tail -n +2 \
    | sed -e 's/content\[\(.*\)\]/\1/' \
    | awk '{print $1}' \
    | sort \
    | uniq
}

That, however, does not tell us anything about which core snaps are in use.

For that, we will probably need to iterate through the list of installed snaps and do what I do for chromium here, and filter those out, before we report them as unconnected:

sune@jekaterina:~$ snap info --verbose chromium | grep 'base:' | awk '{ print $2 }'
core22
sune@jekaterina:~$
-2
snap remove <snap name>

Is a sledgehammer, but will fail stating dependency if one exists.

E.g. with firefox snap installed, attempt to remove its core framework:

snap install firefox
snap remove core20

Error states snap is being used by firefox.

There are also softer dependencies which are in connections, e.g.

snap install firefox
snap connections | grep gtk-common-themes
snap remove gtk-common-themes