How can I disable automatic update for a single snap in Ubuntu?

The recommended way for a system wide installation of Intellij idea is to use snap. When I do that, snap updates the IDE installation which is a big problem for me because updating the development environment causes issues for me and as a developer I'd like strict control of my development environment.

If I disable snap, then I cannot even start the IDE. Google searches return nothing but meaningless long flame wars or complete suspension/disabling of snap.

Is there any way of simply telling snap not to update a piece of software while keeping all else up to date?. I'm using Ubuntu 18.04


You can not. The only thing you can do is delay the update.

From the manual:

Automatic refresh

By design, non-devmode snaps installed from the store are automatically updated on a regular cadence. By default, the snapd daemon checks for updates 4 times each day.

Controlling refresh frequency

Sometimes the user wishes to have snaps refresh at known times, rather than the default. This can be achieved with the snap set system refresh.timer command. The user can specify a range of days or times when they’d prefer refreshes to occur. The following example sets the snapd daemon to refresh snaps only between 4AM and 7AM and between 7PM and 10:10PM.

snap set system refresh.timer=4:00-7:00,19:00-22:10

In theory you could alter the refresh frequency ever day where you keep moving the update moment into the future but this will not work. The snap will get updated at some point (and just ignore your refresh frequency).

See this discussion and the topics from niemeyer.

In that same link post #9 from mwinter (2017) would suggest 2 things:

Me (personally) could do this. But then I rather dislike doing any [additional] filtering on a router as this could cause issues in the future… It also blocks other snap’s and potential more (not sure what all would be at the same location) Another (in my opinion simpler) solution is to download the snap and install it locally - not from store.

  1. block using a firewall rule. That would kill all snap updates. Not a single one.
  2. remove the snap installed from the store and use a locally installed one.

There's two options:

Option 1: --devmode

Although All snaps are updated regularly, snaps installed with --devmode won't be updated because that would potentially obliterate the changes you're ostensibly working on in the snap.

For example, if you'd like to install Package and keep running the same version for the duration of a project that you and your team are working on, thereby removing any risk of regressions like broken plugins, then use these commands:

snap install package
snap list package
snap refresh --devmode --channel 2019.3/stable package

The first gets it into your system. The second lists the available versions. The third sets it to the specific version you want, and enables --devmode so that it will not get automatically refreshed.

Option 2: refresh.hold

You can also configure snap to hold refresh activity until a specific date:

sudo snap set system refresh.hold="2030-01-01T01:00:00-01:00"

and then also:

sudo crontab -e

and add the following:

# prevent snap updates entirely:
1 1 1 * * /usr/bin/snap set system refresh.hold="2030-01-01T01:00:00-01:00"  

This would prevent automated snap updates until the start of 2030 GMT

The plus to this method is that you can use confinement. The drawback is that you need to refresh all your snaps manually.


Necromancing.
There's no option for a single snap, only for all snaps.

A) You can set snap to not refresh on metered-connections

sudo snap set system refresh.metered=hold

B) You can tell snap to only update at specific times

sudo snap set system refresh.timer=sat,23:00~23:59,,sun,23:00~23:59
snap refresh --time

for syntax, see syntax documentation on snapcraft.io.

C) You can set a bogus-proxy for snapd:

snap set system proxy.http="http://127.0.0.1:1111"
snap set system proxy.https="http://127.0.0.1:1111"

D) You can block snapcraft on the firewall

iptables -F
iptables -A OUTPUT -d api.snapcraft.io -j DROP
iptables-save

iptables syntax

E) You can disable snap-refresh by setting the next refresh far into the future

sudo snap set system refresh.hold="2999-01-01T01:00:00-01:00"

To update snap manually

sudo snap refresh

To just list what snaps will be updated:

sudo snap refresh --list

To get info on a specific package, e.g. Chromium:

sudo snap info chromium

And to undo a hold:

sudo snap set system refresh.hold="$(date --date='today-30 days' +%Y-%m-%dT%H:%M:%S%:z)"

To just hold updates until a presentation is done (e.g. update only 30 days)

sudo snap set system refresh.hold="$(date --date='today+30 days' +%Y-%m-%dT%H:%M:%S%:z)"


Note:

The maximum number of days you can hold updates for is 60.