What is Snap
Snap is a software packaging and deployment system (similar to deb) developed by Canonical for Linux. It has version control capabilities which help maintain multiple releases of a particular application (aka snaps).
Though it is a proprietary solution from Canonical, Snap is available for other linux distros like Fedora, CentOS and Manjaro as well.
From a single build, a snap (application) will run on all supported Linux distributions on desktop, in the cloud and in IoT. Applications managed by snap are updated (refreshed) automatically and the update schedule can be configured.
Ubuntu for example provides a lot of application via the snap store instead of the older apt repositories. Some of the important apps include:
- Chromium browser
- Firefox Browser
- Opera Browser
On ubuntu and ubuntu-based distros, you have to use the snap store to install the latest version of these apps, as they would no longer be maintained at the apt repositories.
Lets take a look at various components of the snap ecosystem.
Essential SNAP components that you need to know about.
snapd -Background daemon that maintains your snap packages
snap - Command line utility to manage (install, remove, maintain versions) of snaps.
snapcraft - Command line tool that allows developers to build and publish their applications as snaps based on the configuration file (snapcraft.yaml).
snapstore - A central repository for publishing snaps. Linux users can install snaps from the snapstore.
On Ubuntu and its variants snap is installed and enabled by default. On other debian like variants, you can install the snap manager to install packages from the snap repository.
In this article, we will be focusing on the snap command line utility. For the purpose of demonstration, I will be using – Kali GNU/Linux 2022.4
Before installing snap, you need to ensure that it is not pre-installed in your Linux environment. You can check the same with the following:
Refer to the documentation of snap command line for specific Linux distributions.
Installing snapd | Snapcraft documentation
To check whether snap is installed in your system, you can run the following:
$ snap --version Could not find command-not-found database. Run 'sudo apt update' to populate it. snap: command not found
As evident from the above screenshot, we don’t have snap installed. Let’s proceed towards installing snap utility.
For installing snap, use the following commands:
$ sudo apt install snapd Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: snapd 0 upgraded, 1 newly installed, 0 to remove and 1340 not upgraded. Need to get 14.8 MB of archives. After this operation, 61.4 MB of additional disk space will be used. Get:1 http://http.kali.org/kali kali-rolling/main amd64 snapd amd64 2.57.6-1+b2 [14.8 MB] Fetched 14.8 MB in 4s (3,458 kB/s) Selecting previously unselected package snapd. (Reading database ... 393607 files and directories currently installed.) Preparing to unpack .../snapd_2.57.6-1+b2_amd64.deb ... Unpacking snapd (2.57.6-1+b2) ... Setting up snapd (2.57.6-1+b2) ... snapd.aa-prompt-listener.service is a disabled or a static unit, not starting it. snapd.apparmor.service is a disabled or a static unit, not starting it. snapd.recovery-chooser-trigger.service is a disabled or a static unit, not starting it. snapd.seeded.service is a disabled or a static unit, not starting it. snapd.service is a disabled or a static unit, not starting it. snapd.socket is a disabled or a static unit, not starting it. Processing triggers for desktop-file-utils (0.26-1) ... Processing triggers for man-db (2.11.0-1+b1) ... Processing triggers for dbus (1.14.4-1) ... Processing triggers for mailcap (3.70+nmu1) ... Processing triggers for kali-menu (2022.4.1) ...
After installation of snapd, we need to activate apparmor service for snapd. To read more on apparmor service refer to the following article – AppArmor – Ubuntu Wiki.
Enable apparmor with the following command:
$ systemctl enable --now snapd apparmor Synchronizing state of apparmor.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable apparmor Created symlink /etc/systemd/system/multi-user.target.wants/snapd.service → /lib/systemd/system/snapd.service. Created symlink /etc/systemd/system/sysinit.target.wants/apparmor.service → /lib/systemd/system/apparmor.service.
If you are not logged in as the root user, you will be prompted for password several times during the above process.
Once apparmor is enabled, verify snap installation with the following command:
$ snap --version snap 2.57.6-1+b2 snapd 2.57.6-1+b2 series 16 kali 2022.4 kernel 6.0.0-kali3-amd64
To test our snap installation, we will use the hello-world snap to ensure snap is working correctly.
$ snap install hello-world 2023-02-15T06:17:03-05:00 INFO Waiting for automatic snapd restart... Warning: /snap/bin was not found in your $PATH. If you've not restarted your session since you installed snapd, try doing that. Please see https://forum.snapcraft.io/t/9469 for more details. hello-world 6.4 from Canonical✓ installed WARNING: There is 1 new warning. See 'snap warnings'.
While installing the hello-world snap, if you get the warning "snap/bin was not found in your $PATH", you can resolve it by setting the bin folder of snap to the environment variable PATH.
$ export PATH="/snap/bin:$PATH"
Check the environment variable path with the following command:
$ echo $PATH /snap/bin:
For more information regarding missing binaries in snap installation refer to – Troubleshooting | Snapcraft documentation
Verify the hello-world snap installation.
$ hello-world Hello World!
We can see our snap installation is successful!
Searching applications using snap
Before installing any application, you can check it out in the snapstore. You can search for a particular category of application.
If the application belongs to a certain category, let’s say media player, we can search for available packages through the following command.
I will be using "vlc" as the application (snap) for the demonstration.
$ snap find "media player" Name Version Publisher Notes Summary vlc 3.0.18 videolan✓ - The ultimate media player foobar2000 1.6.16 mmtrt - foobar2000 is an advanced freeware audio player. tizonia 0.22.0 tizonia - Cloud music from the Linux terminal audio-recorder 3.0.5+rev1432+pkg-7b07 brlin - A free audio-recorder for Linux (EXTREMELY BUGGY) ...
Now let's say we want information on installing "vlc" from the above list. Command for fetching information on a particular application is:
Getting application details
The following command will fetch detailed information about a snap package:
snap info vlc
Here is an example:
$ snap info vlc name: vlc summary: The ultimate media player publisher: VideoLAN✓ store-url: https://snapcraft.io/vlc contact: https://www.videolan.org/support/ license: GPL-2.0+ description: | VLC is the VideoLAN project's media player. Completely open source and privacy-friendly, it plays every multimedia file and streams. It notably plays MKV, MP4, MPEG, MPEG-2, MPEG-4, DivX, MOV, WMV, QuickTime, WebM, FLAC, MP3, Ogg/Vorbis files, BluRays, DVDs, VCDs, podcasts, and multimedia streams from various network sources. It supports subtitles, closed captions and is translated in numerous languages. snap-id: RT9mcUhVsRYrDLG8qnvGiy26NKvv6Qkd channels: latest/stable: 3.0.18 2022-10-28 (3078) 336MB - latest/candidate: 3.0.18 2022-10-28 (3078) 336MB - latest/beta: 3.0.18-83-g4243386635 2023-02-15 (3312) 336MB - latest/edge: 4.0.0-dev-22660-ge9705c553c 2023-02-15 (3313) 691MB - WARNING: There is 1 new warning. See 'snap warnings'.
In the above excerpt, we can see the author information and the various builds (stable, candidate, beta, edge) of the application that we can install.
To install an application, we can use the following command. It installs the stable release
snap install vlc
To install a specific release like beta for example, use the following command.
$ snap install --beta vlc vlc (beta) 3.0.18-83-g4243386635 from VideoLAN✓ installed
You cannot install two versions of a snap using the install command. For managing two versions you have to use the refresh and revert commands discussed later in this article.
Listing installed snaps
To check the currently installed snaps use the list option with the command.
$ snap list Name Version Rev Tracking Publisher Notes core 16-2.58 14447 latest/stable canonical✓ core core18 20230118 2679 latest/stable canonical✓ base hello-world 6.4 29 latest/stable canonical✓ - vlc 3.0.18-83-g4243386635 3312 latest/beta videolan✓ -
We can see the installed snaps and their metadata in the list.
You can also list versions of a particular application using the following:
$ snap list vlc Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/beta videolan✓ - $ snap list -all vlc Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ disabled vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ -
The command "snap list all vlc" shows all the versions of vlc installed and their state. We can see the 3.0.18-x version of vlc is in disabled state. You will read about managing various versions of a snap in the next few sections.
Updating an application
Applications can be updated individually or all at once using snap. Similarly, updated applications may be reverted to previous builds.
Command for updating snap:
$ sudo snap refresh vlc
Command to refresh using a specific channel:
$ snap refresh --edge vlc vlc (edge) 4.0.0-dev-22660-ge9705c553c from VideoLAN✓ refreshed
$ snap list --all vlc Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ disabled vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ -
The channel information can be obtained with the help of the info command discussed previously. We can see "vlc" has two versions, edge and beta, from their respective versions. On refreshing the app to a particular build, the new version update is automatically enabled and the previous version is disabled.
Updating all applications
If you are a regular ubuntu user who updates packages once in a while, then you can issue a simple command to update all the installed snaps in one go.
sudo snap refresh
The above command will update all packages.
Command for reverting snap:
$ sudo snap revert "vlc" vlc reverted to 3.0.18-83-g4243386635 $ sudo snap list --all "vlc" Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ - vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ disabled
On reverting an application, the previous state is restored. We can see 3.0.18-x is active again.
Command to revert an application to a particular revision:
$ sudo snap revert --revision=3313 vlc vlc reverted to 4.0.0-dev-22660-ge9705c553c $ sudo snap list --all "vlc" Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ disabled vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ -
The revision version can be obtained from "sudo snap list --all "vlc"" under "Rev".
Once the revert command is run for any application, the previously active version of the build is enabled and the other versions are disabled.
Disabling and enabling snap
We can disable and enable snaps. This is not version specific; it disables/enables an app as a whole. If you want to use a particular version of an application, we can do so with "refresh" and "revert" commands discussed earlier.
Command to disable snaps:
$ snap disable vlc vlc disabled
Now check the status of that particular snap package with the following command and note that it shows disabled.
$ sudo snap list --all vlc Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ disabled vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ disabled
We can see that all versions of VLC are disabled.
Command to enable snaps:
$ sudo snap enable vlc vlc enabled $ sudo snap list --all "vlc" Name Version Rev Tracking Publisher Notes vlc 3.0.18-83-g4243386635 3312 latest/edge videolan✓ disabled vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ -
We can see the previously active version of VLC is enabled again.
We can remove a particular version of a snap or the entire snap package itself.
Command to uninstall a snap completely:
$ snap remove vlc vlc removed $ sudo snap list --all vlc error: no matching snaps installed
To remove a particular version of an application:
$ snap remove --revision=3312 vlc vlc (revision 3312) removed
You cannot remove a particular version of an application which is in enabled state. You have to revert, refresh or disable the application as a whole or to a specific version for doing so.
$ sudo snap list --all vlc Name Version Rev Tracking Publisher Notes vlc 4.0.0-dev-22660-ge9705c553c 3313 latest/edge videolan✓ - $ snap remove --revision=3313 vlc error: cannot remove "vlc": cannot remove active revision 3313 of snap "vlc"
Snap vs APT
There is a discussion on reddit, about the pros and cons of the snap packaging system. Check it here.
There is a debate, on whether you should use the snap package manager or your distro's default package management system. Often times a package might be available from both channels.
Snap packages are known to have slower startup times compared to packages installed from default distros. This is because the snap packages have a different structure to enable portability.
If you want the best speed, then you should ideally install the package from the distro's default repository like apt on ubuntu or dnf on fedora and avoid snap completely. However if a particular package is available only via snap then you have no choice.
You can choose to completely remove the snap package manager from your linux system but then you would lose access to apps that are exclusively available via snap only.
After mastering the basic commands, next up you can read on how to create your own snaps and publish them on snap store, if you are a developer. Check out this resource – Create your first snap | Ubuntu
Readings on security vulnerabilities detected in snap – USN-5292-1: snapd vulnerabilities | Ubuntu security notices | Ubuntu