5

Is there an equivalent snap command that does for Snaps what apt-get autoremove / apt-get autopurge does for Apt packages? (Also available as apt autoremove...)

Update 3: For the curious and those who end up here from Google, the equivalent command for FlatPak is flatpak uninstall --unused.

Update: I wanted to clarify the question after receiving an answer which states:

Snaps do not have dependencies like apt, so an equivalent to autoremove seems unnecessary.

This is incorrect. Consider the following (just one example of many):

$ snap list 
Name               Version          Rev    Tracking         Publisher      Notes
bare               1.0              5      latest/stable    canonical✓     base
core               16-2.57.6        14399  latest/stable    canonical✓     core
core18             20221212         2667   latest/stable    canonical✓     base
core20             20221123         1738   latest/stable    canonical✓     base
$ sudo snap install nvim --classic 
nvim v0.8.1 from neovim-snap (neovim-snap) installed
$ snap list 
Name               Version          Rev    Tracking         Publisher      Notes
bare               1.0              5      latest/stable    canonical✓     base
core               16-2.57.6        14399  latest/stable    canonical✓     core
core18             20221212         2667   latest/stable    canonical✓     base
core20             20221123         1738   latest/stable    canonical✓     base
core22             20221129         444    latest/stable    canonical✓     base
nvim               v0.8.1           2775   latest/stable    neovim-snap    classic
$ sudo snap remove nvim 
nvim removed
$ snap list 
Name               Version          Rev    Tracking         Publisher      Notes
bare               1.0              5      latest/stable    canonical✓     base
core               16-2.57.6        14399  latest/stable    canonical✓     core
core18             20221212         2667   latest/stable    canonical✓     base
core20             20221123         1738   latest/stable    canonical✓     base
core22             20221129         444    latest/stable    canonical✓     base
$

Before installing nvim, core22 was not installed. After removing it, core22 is left behind even though nothing depends on it now.

Update 2: In the above example, the installed dependency core22 is a base snap. Here's another example which demonstrates that the same issue is also present for non-base dependencies:

$ sudo snap list 
Name               Version          Rev    Tracking         Publisher      Notes
bare               1.0              5      latest/stable    canonical✓     base
core               16-2.57.6        14399  latest/stable    canonical✓     core
core18             20221212         2667   latest/stable    canonical✓     base
core20             20221123         1738   latest/stable    canonical✓     base
core22             20221129         444    latest/stable    canonical✓     base
$ sudo snap install falkon 
falkon 22.08.2 from KDE✓ installed
$ snap list 
Name                                  Version          Rev    Tracking         Publisher      Notes
bare                                  1.0              5      latest/stable    canonical✓     base
core                                  16-2.57.6        14399  latest/stable    canonical✓     core
core18                                20221212         2667   latest/stable    canonical✓     base
core20                                20221123         1738   latest/stable    canonical✓     base
core22                                20221129         444    latest/stable    canonical✓     base
falkon                                22.08.2          86     latest/stable    kde✓           -
kde-frameworks-5-98-qt-5-15-6-core20  5.98.0           9      latest/stable    kde✓           -
$ sudo snap remove falkon 
falkon removed
$ snap list 
Name                                  Version          Rev    Tracking         Publisher      Notes
bare                                  1.0              5      latest/stable    canonical✓     base
core                                  16-2.57.6        14399  latest/stable    canonical✓     core
core18                                20221212         2667   latest/stable    canonical✓     base
core20                                20221123         1738   latest/stable    canonical✓     base
core22                                20221129         444    latest/stable    canonical✓     base
kde-frameworks-5-98-qt-5-15-6-core20  5.98.0           9      latest/stable    kde✓           -
$ 

After installing and then removing the falkon snap, the unused dependency kde-frameworks-5-... is left behind.

11
  • 1
    @Terrance in the sense that nvim needs it, it's a "dependency". Yes it's also a base snap. And I am looking for an apt auroremove analog exactly because it did not remove when I removed nvim.
    – P Varga
    Commented Dec 21, 2022 at 8:46
  • 1
    The answer to this question might be interesting for you.
    – mook765
    Commented Dec 21, 2022 at 11:26
  • 1
    Auto-removal of base snaps if they are not needed is something that Canonical has not included into snaps. If you feel this should be added you are more than welcome to contribute or file a bug against snapd for a feature request.
    – Terrance
    Commented Dec 21, 2022 at 14:43
  • 1
    @Terrance my example with nvim and core22 showed a "base snap" being installed. Now I've added another example with falkon which shows the same happens for a non-base dependency
    – P Varga
    Commented Dec 21, 2022 at 18:18
  • 1
    By the way, non-base dependencies can be removed but the snap may not show correctly when it is removed, but the app itself will still work.
    – Terrance
    Commented Dec 21, 2022 at 19:34

2 Answers 2

2

Snap AutoCleanUp

A often discussed question ... with a bunch of half-answers.

Since snap has no package systems that just upgrades in place , snap pulls dependencies with the packages and also keeps a copy of the last n versions of snaps

( and you are right if you think that snap uses your local storage like a mirrored registry with the last n versions )

Current State of Snap Auto-Cleaning:

In fact there is a Feature proposal since 2020 ( ~3 Years ) , so maybe spread some votes there ..

Snap Clean-Up / Auto-Purge Ways:

The behaviour closest to "auto-pruning" you can get:

  • Engage the auto-clean script to get rid of old versions ( found here )

  • disable auto-snapshots , their manual says it all:

    sudo snap set system snapshots.automatic.retention=no will disable it

    Automatic snapshot retention time is configured with the snapshots.automatic.retention system option. The default value is 31 days, and the value needs to be greater than 24 hours

    ...

    Disabling automatic snapshots will not affect preexisting, automatically generated snapshots, but only those generated by subsequent snap removals.

  • clean up the snapshots, there is a very good example script

There is no "exact-same" apt(-get) way of saving more space with snap , but amongst the top-tips there are:

  • Lower the "old versions" snapd keeps: sudo snap set system refresh.retain=2

    The refresh.retain value can be a number between 2 and 20. The default is refresh.retain=3 on Ubuntu Core systems and refresh.retain=2 on classic Ubuntu systems, such as those running Ubuntu 18.04 LTS (Bionic Beaver) and Ubuntu 16.04 LTS (Xenial Xerus).

  • clear the cache: sudo find /var/lib/snapd/cache/ -exec rm -v {} \; # Remove cache

The "Dangerous" non-moving part: locking against updates with refresh --hold

Preamble: You might run into outdated software and resulting security issues , so please be careful and update regularly by reinstalling or unholding the lock.

Another question also included:

even limiting unattended installation to Canonical-supported software

well

There was currently no way found to do this, except "pinning"( snap term "refresh hold")

How-To: snapd pinning

  • since 2.58+, there is refresh lock holding ( apt pinning equivalent )
  • it might be issued for one or all packages , with and without timelimit
  • snap refresh --hold "should" lock all updates
  • a specific example is sudo snap refresh --hold=24h firefox

How-To: update snapd "pinned" software

  • Variant A to update (firefox example), either sudo snap remove --purge firefox;sudo snap install firefox;sudo snap refresh --hold

  • Variant B to update sudo snap refresh --unhold firefox;sudo snap refresh firefox;sudo snap refresh --hold

0

After looking for a while, it is clear that there is no equivalent command currently.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .