Controlling snap package update time

Latest update May 08, 2024

One of the main complains of windows users is that at any given time it might decide to stop everything and run an update. I have been experiencing the same behavior by snap on my ubuntu machine. It became quite annoying, specially when updating any software while I was using it, such any of the editors I use for work or even slack while talking to people.

To overcome this I found two options, either forbidding snaps from been updated, or reduce the allowed update time for all snaps. I went for the second.

Reduce update time frame

To set the allowed time frame for updates is done with the system refresh.timer variable. I allow my snaps to be refreshed between 4.00 and 7.00 and also between 19.00 and 22.10:

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

For fancier schedules check the snap timer string formatting.

To check when was the last time and the next time when the refresh action did or will take place run:

snap refresh --time

To check if there are available snaps updates to install:

snap refresh --list

Update snaps right now

Of course we may want to update any package at any given time, so to force the snap refresh outside of the allowed time span:

snap refresh

Find out latest snap update time

Checkout latest updated snaps:

snap changes

The command above only returns information about the snaps that were updated on the last refresh, so it is not reliable to check the latest refresh of any given package. That information can be found with:

snap info <snap-name>

To generate a list with the latest update time for each snap run:

snap list | awk 'NR > 1 {print $1}' | xargs -i sh -c 'snap info {} | grep "name\|refresh-date" && echo " "'

Update

To also print the version of the snap together with the latests update time:

snap list | awk 'NR > 1 {print $1}' | xargs -i sh -c 'snap info {} | grep "name\|refresh-date\|installed" && echo " "'