Almost everyone knows how to install apt packages from the terminal on Linux. We know how to do sudo apt upgrade and sudo apt update.
The question is, how many of us know how to update a snap package from a snap store? Snap is an open-source toolkit that allows you to create and manage your applications at scale on Linux.
It's possible to update Snap packages from Ubuntu Software, Kubuntu Discover, or any other snap packages store. But we can also update them from the terminal.
If you are wondering how to snap update package on your favorite Linux distribution, this tutorial is for you.
How Update Snapd Works
Snapd daemon handles all the updates for snaps installed on a Linux system. Once a snap is installed, snapd daemon will automatically keep it up to date. This is done by regularly checking for updates from the snap store and installing any available updates.
This update check is known as refresh, which happens 4 times daily. Although, when and often this update should take place can be modified as we deem fit using the snap refresh command.
The command can do more than modify the time we want an update to occur. With the time option, we can check when the last update was carried out and when the next update is scheduled.
The command line code is as follows:
sudo snap refresh --time
From the image above, the timer tells us how and when a refresh is scheduled - we've got it scheduled between 2:00 am and 5:00 am. The last update took place three days ago at 8:16 PM West Africa Time and the next update has not been scheduled.
How to List Updates
With the snap list command, we can check all the snaps that will be updated with the next refresh. To do this, we will enter the following command.
sudo snap refresh --list
We'll quickly go over the image above. During the next refresh, two snaps will be updated. The name, size, and version of the snaps were all displayed. Canonical provides services and solutions for Ubuntu, so the snaps would be from them.
How to Update specific snap package
Earlier, we discussed how snapd automatically checks for updates and installs them if there are any. With the snap command, we can also check if there is an update for a particular snap package. To do this, we will run the command:
sudo snap refresh <Application-name>
From the image above, we ran sudo snap refresh firefox to see if there was an update for Firefox. But, firefox was already up to date.
How to Manually Update All Packages
Now, we will focus on how to manually manage snap package updates on Linux. It is possible to manually update all installed packages to their latest version with one command.
The command line code is as follows:
sudo snap refresh
It is easy to understand the image above. We wanted to manually update all installed packages. Updates have been made to Snapd version 2.57.6 from Canonical.
List Snap Update Changes
It is time we talked about two essential commands - snap changes and snap change <change-id>. With the first command, we can check the details of the changes made during the last refresh. While the second command allows us to see, the actions performed by a specific change.
The syntax for these commands is as follows:
sudo snap changes sudo snap change <change-id>
Two changes were made during the last refresh, as shown in the above image. There is an ID for these changes, a time stamp, a status, and a summary of what was done. By using their ID numbers, we then examined the actions taken by each change.
How to Control Package Updates
A few different approaches can be taken when managing packages installed updates in Linux. But, we will focus on the two most crucial strategies in this article - the hold command and system settings.
Using hold command
The snap refresh --hold command is used to update software but hold back its release. This could be for only one package or all the snap packages available on the Linux system. This hold can be for a specific period or indefinitely, depending on how you want it.
The syntax is as follows:
sudo snap refresh --hold=<duration> <snap1> <snap2>...
Duration can be in the hour(s), minute(s), or second(s). It could as well be the combination of the three. In a case where duration is not specified, it defaults to forever. A value of forever means updates are postponed indefinitely.
The command will hold all currently installed snap packages if snaps are not specified. The command will only hold the specified snap package(s) if one or more snaps are selected.
When we specify one or more snap packages with the snap hold command on Linux, the hold is effective on the specific snaps auto-refreshes and general requests from "snap refresh." However, a refresh targeting a specifically held software will not be blocked.
If no snaps are specified, refresh hold applies to snap packages installed on the system. However, the hold only applies to auto-refreshes. It does not affect general refresh requests from "snap refresh." As well as specific snap requests from a particular software, i.e., snap refresh target-snap."
We have learned to put a hold on a particular snap package and all the snap packages installed on a system. Let's quickly discuss how we can remove these hold(s).
The command below can remove a refresh hold on a particular snap or all the snap packages when no snap is specified.
For a single snap, we will use the following:
sudo snap refresh --unhold chrome
For all snap packages, we will use the following:
sudo snap refresh --unhold
Users have some freedom when using the snap package manager. Users can choose how updates are handled. This update is based on one of the following options:
This option can define the schedule and refresh frequency for installed snaps.
The command below tells the system to perform the snap refresh between 2:00 am and 8:00 am and between 2:00 pm and 6:00 pm.
sudo snap set system refresh.timer=2:00-8:00,14:00-18:00
To confirm our timer has been set, we can run the command below in our terminal:
sudo snap refresh --time
We've got the next refresh scheduled between 2:00 am and 8:00 am and between 2:00 pm and 6:00 pm, exactly what we wanted. The last update took place four days ago at 8:16 PM West Africa Time and the next update is scheduled for the same day at 02:00 PM West Africa Time.
Refresh.metered is useful when a metered connection is detected, such as an LTE connection, and we need to pause and re-enable the refresh process.
To hold the refreshing of snap packages when on a metered connection, we will execute the command below in our terminal:
sudo snap set system refresh.metered=hold
And when we need to resume refreshing, we will execute the following in our terminal:
sudo snap set system refresh.metered=null
Refresh.retain allows us to set the maximum number of a snap's revisions that will be retained after the next refresh. This number can range between 2 and 20. And by default, it is set to 2.
To set it to a different value, we will run the command below:
sudo snap set system refresh.retain=7
As we have seen, updating snaps is a simple process that can be completed in just a few steps. All you need is a few minutes and the correct set of commands to save time. From our personal experience, the man page is a great resource if you need more information.
We hope you can comfortably manage snaps without any difficulty.