The previous chapter explored the use of the Advanced Packaging Tool (APT) to install and update software packages on an Ubuntu system. In recent years a new package management system called Snap has been under development by the Ubuntu team at Canonical, Ltd. Although there are no official plans to replace APT entirely with Snap, the list of packages that can now be installed as “snaps” continues to grow.
The goal of this chapter is to introduce the Snap system, highlight the key advantages it has over the APT system and to outline how to use the snap command-line tool to install and manage snap -based software packages.
Managing Software with Snap
The apt tool installs software that is packaged in .deb files. A package installed using apt will often be dependent upon other packages that will also need to be installed in order to function. During an installation, apt will also download and install these additional package dependencies. Consider a graphics design app which depends on a particular imaging library. During installation, apt will install the graphics app package in addition to the package containing the library on which it depends. Now, assume that the user decides to install a different graphics tool that also relies on the same graphics library. Usually this would not be a problem since the apps will both share the same library, but problems may occur if the two apps rely on different versions of the library. Installing the second app may, therefore, stop the first app from working correctly. Another limitation of apt and .deb packages is that it is difficult to have two different versions of the same tool or app installed in parallel on a system. A user might, for example, want to keep version 1.0 of the graphics app installed while also trying out the latest beta release of the 2.0 version. After trying out version 2.0, the user may then want to remove version 1.0, leaving the new version installed, a task that would be hard to achieve using apt.
The snap system has been designed specifically to address these types of shortcomings. The snap tool installs .snap packages that contain all of the libraries and assets that are required for the software to function. This avoids the need to install any dependencies as separate, independent packages. Once a snap has been installed it is placed in a self-contained location so that no dependencies are shared with other packages. Our hypothetical graphics apps, for example, each have their own copies of the exact imaging library version used by the app developer which cannot be deleted, replaced with an incompatible version or overwritten by any other package installations.
Of course the use of snaps results in larger package files which leads to longer package download times, slower installation performance and increased disk space usage. That being said, these shortcomings are generally more than outweighed by the advantages of snap packages.
Snap also supports the concept of channels which allow app developers to publish different versions of the same app. Snap channels are the mechanism by which multiple versions of the same software are able to be installed in parallel.
Basic Snap Commands
Although many software packages are still provided in .deb format and installed using apt, the number of apps and tools now provided in snap format is increasing rapidly. In fact, all of the software listed in the Ubuntu Software tool (outlined previously in the chapter entitled A Guided Tour of the Ubuntu 22.04 GNOME 42 Desktop) are packaged and installed using snap. Snap-based software may also be installed using the snap command-line tool, the basics of which will be covered in this section.
To list the snap packages that are available for a specific category of software, run a command similar to the following:
# snap find "image editor" Name Version Publisher Notes Summary gimp 2.10.18 snapcrafters - GNU Image Manipulation Program paintsupreme-3d 1.0.41 braindistrict - PaintSupreme 3D . .Code language: plaintext (plaintext)
The above command will list all snap packages available for download and installation containing software related in some way to image editing. One such result will be the gimp image editor. Details about the gimp snap can be found as follows:
# snap info gimp name: gimp summary: GNU Image Manipulation Program publisher: Snapcrafters✪ store-url: https://snapcraft.io/gimp contact: https://github.com/snapcrafters/gimp/issues license: GPL-3.0+ description: | Whether you are a graphic designer, photographer, illustrator, or scientist, GIMP provides you with sophisticated tools to get your job done. You can further enhance your productivity with GIMP thanks to many customization options and 3rd party plugins. This snap is maintained by the Snapcrafters community, and is not necessarily endorsed or officially maintained by the upstream developers. Upstream Project: https://www.gimp.org/ snapcraft.yaml Build Definition: https://github.com/snapcrafters/gimp/blob/master/snap/snapcraft.yaml snap-id: KDHYbyuzZukmLhiogKiUksByRhXD2gYV channels: latest/stable: 2.10.30 2022-08-19 (393) 546MB - latest/candidate: ↑ latest/beta: ↑ latest/edge: 2.10.32 2022-08-23 (399) 547MB - preview/stable: – preview/candidate: – preview/beta: – preview/edge: 2.99.10 2022-08-17 (397) 650MB -Code language: plaintext (plaintext)
The snap find command can also be used to find a specific package by name, together with other packages that provide similar features. Searching for the VLC media player app, for example, also lists similar software packages:
$ snap find vlc Name Version Publisher Notes Summary vlc 3.0.18 videolan - The ultimate media player orion-desktop 2.0.0 keshavnrj - Complete torrent client and streamer for Linux Desktop gridplayer 0.4.3 vzhd1701 - Play multiple videos side-by-side mjpg-streamer 2.0 ogra - UVC webcam streaming tool audio-recorder 3.0.5+rev1432+pkg-7b07 brlin - A free audio-recorder for Linux (EXTREMELY BUGGY) ustreamer 5.41 pgentili - Lightweight and fast MJPEG-HTTP streamerCode language: plaintext (plaintext)
The snap list command-line option can be used to obtain a list of snap packages that are already installed on a system:
$ snap list Name Version Rev Tracking Publisher Notes bare 1.0 5 latest/stable canonical base canonical-livepatch 10.6.0 235 latest/stable canonical - core 16-2.59.5 15511 latest/stable canonical core core20 20230622 1974 latest/stable canonical base core22 20230703 817 latest/stable canonical base firefox 115.0-2 2850 latest/stable/… mozilla - gnome-3-38-2004 0+git.efb213a 143 latest/stable/… canonical - gnome-42-2204 0+git.ff35a85 120 latest/stable canonical - . .Code language: plaintext (plaintext)
To install a snap package (for example, to install the Remmina remote desktop tool), run the snap command with the install option followed by the name of the package to be installed:
# snap install remminaCode language: plaintext (plaintext)
To remove a snap package, simply specify the package name when running snap with the remove option:
# snap remove remminaCode language: plaintext (plaintext)
Working with Snap Channels
If no channel is specified when performing an installation, snap will default to the stable channel. This ensures that the latest reliable version of the software is installed. To perform the installation from a different channel, begin by identifying the channels that are currently available for the required package using the snap info option:
# snap info remmina name: remmina summary: Remote Desktop Client . . channels: latest/stable: v1.4.29 2022-12-20 (5599) 146MB - latest/candidate: ↑ latest/beta: ↑ latest/edge: v1.4.31+git102.f5485fcfd 2023-07-17 (5925) 144MB -Code language: plaintext (plaintext)
From the above output we can see that while the stable version of the Remmina app is v1.4.3+git13.688f5f75 a more recent version is available in the edge channel.
Of course the candidate, beta and edge channels provide access to the software in increasingly unstable forms (referred to as risk level), but if you would like to try out an early access version of upcoming features of a package, install from a higher risk channel. For example:
# snap install --channel=edge remminaCode language: plaintext (plaintext)
The channel selection may also be abbreviated to –stable, –candidate, –beta or –edge, for example:
# snap install --edge remminaCode language: plaintext (plaintext)
If the package is already installed, the risk level can be changed using the switch option:
# snap switch channel=edge remminaCode language: plaintext (plaintext)
This will change the channel that snap is tracking for the specified package. The current channel being tracked for a package can be identified using the snap info command:
# snap info remmina name: remmina . . tracking: latest/edge . .Code language: plaintext (plaintext)
Simply running a snap switch command will not immediately refresh the package to use the new channel. To understand how this works it will help to explore the snap refresh schedule.
Snap Refresh Schedule
The snap system includes a background service named snapd which is responsible for refreshing installed snaps based on the channels that they are tracking. By default, snapd performs refresh operations at regular intervals (typically four times a day). To identify when the last refresh was performed, and the next is due, run the following command:
# snap refresh --time timer: 00:00~24:00/4 last: today at 07:23 EDT next: today at 14:25 EDTCode language: PHP (php)
The above output also includes timer information which indicates that the refresh will be performed four times within each 24-hour period:
. . timer: 00:00~24:00/4 . .Code language: plaintext (plaintext)
The snap command can also be used to force a refresh of all installed snap packages as follows:
# snap refreshCode language: plaintext (plaintext)
Alternatively, to refresh a specific package:
# snap refresh remminaCode language: plaintext (plaintext)
To switch a package to a different channel without having to wait for the next snapd service refresh, simply run the snap refresh command as follows, specifying the target channel:
# snap refresh remmina --channel=edgeCode language: plaintext (plaintext)
The snap system also has a set of four properties that may be modified to adjust the refresh schedule used by snapd:
- refresh.timer: Stores the current refresh schedule and frequency.
- refresh.hold: Used to delay refresh operations until the specified day and time (in RFC 3339 format).
- refresh.metered: Pauses refresh operations when network access is via a metered connection (such as a mobile data connection).
- refresh.retain: Used to configure the number of revisions of each snap installation that are to be retained.
For example, to schedule the refresh to occur on weekdays between 1:00am and 2:00am:
# snap set system refresh.timer=mon-fri,1:00-2:00Code language: plaintext (plaintext)
Similarly, the following command will configure refreshes twice every day to occur between the hours of 6:00am and 7:00am, and 10:00pm and 11:00pm:
# snap set system refresh.timer=6:00-7:00,22:00-23:00Code language: plaintext (plaintext)
A full explanation of the timer format and syntax can be found online at the following URL:
After making a change to the timer, be sure to check the settings as follows:
# snap refresh --time timer: mon-fri,1:00-2:00 last: today at 07:23 EDT next: tomorrow at 01:00 EDTCode language: plaintext (plaintext)
To pause refreshes, the date and time at which refreshing is to resume must be specified using the RFC 3339 format, details of which can be found at the following URL:
In summary, the date and time should use the following format:
YYYY-MM-DDTHH:MM.SS<UTC offset>Code language: plaintext (plaintext)
For example, to specify a hold until October 12, 2020 at 3:20am for a system located in New York, the date and time would be formatted as follows:
2020-10-12T03:20:50.0-05:00Code language: plaintext (plaintext)
Note that since New York uses Eastern Standard Time (EST) it has a -5 hour offset from Coordinated Universal Time (UTC-5:00). Having formatted the date and time, the following command would be used to set the hold:
# snap set system refresh.hold="2020-10-12T03:20:50.0-05:00"Code language: plaintext (plaintext)
To check the current hold setting, use snap with the system get option:
# snap get system refresh.hold 2020-10-12T03:20:50.0-04:00Code language: plaintext (plaintext)
To remove the hold, simply assign a null value to the property:
# snap set system refresh.hold=nullCode language: plaintext (plaintext)
The refresh.retain property can be set to any value between 0 and 20, for example:
# snap set system refresh.retain=10Code language: plaintext (plaintext)
Finally, to pause refresh updates while the system is on a metered connection, set the refresh. metered property to hold as follows:
# snap set system refresh.metered=holdCode language: plaintext (plaintext)
As with the hold property, disable this setting by assigning a null value to the property:
# snap set system refresh.metered=nullCode language: plaintext (plaintext)
It is worth noting that some snap packages include their own services, which run in the background when the package is installed (much like the systemd services described in the chapter entitled Managing Ubuntu 22.04 systemd Units). To obtain a list of snap services that are currently running on a system, execute the snap command with the services option:
# snap services Service Startup Current Notes canonical-livepatch.canonical-livepatchd enabled active -Code language: plaintext (plaintext)
The above output indicated that the LivePatch snap service is currently enabled and active. To stop or stop a service the following snap commands can be used:
# snap start canonical-livepatch.canonical-livepatch # snap stop canonical-livepatch.canonical-livepatchCode language: plaintext (plaintext)
Similarly the snap enable and disable options may to used to control whether or not a service starts automatically on system startup:
# snap enable canonical-livepatch.canonical-livepatch # snap disable canonical-livepatch.canonical-livepatchCode language: plaintext (plaintext)
If the snap service generates a log file, that file can be viewed as follows:
# snap logs canonical-livepatch 2020-05-06T13:21:58Z canonical-livepatch: No payload available. 2020-05-06T13:21:58Z canonical-livepatch: during refresh: cannot check: No machine-token. Please run ‘canonical-livepatch enable’! . .Code language: plaintext (plaintext)
It is also still possible to manage snap services using the systemctl command. This usually involves prefixing the service name with “snap.”. For example:
# systemctl status snap.canonical-livepatch.canonical-livepatchdCode language: plaintext (plaintext)
Until recently, all Ubuntu software packages were stored in .deb files and installed using the Advanced Packaging Tool (APT). An increasing number of packages are now available for installation using Snap, a package management system developed by Canonical, Ltd. Unlike apt packages, snap bundles all of the dependencies for a package into a single .snap file. This ensures that the software package is self-contained with its own copy of all of the libraries and assets needed to run. This avoids the potential conflicts of packages relying on different versions of the same shared assets and libraries. The Snap system also allows different versions of the same packages to be installed in parallel. All of the software listed in the Ubuntu Software tool are supplied as snap packages. In addition, snap can be used to install, remove and manage packages from the command-line.