How to install and use snaps on Fedora

Developed by Canonical, the company behind Ubuntu, and originally meant to be used on the latter, the Snappy package manager is a free and open source software used to install and manage snap packages. The purpose of Snap packages, just like flatpaks, is to distribute sandboxed and self-contained applications (applications are packaged together with their dependencies).

The Snappy package manager and its infrastructure landed on distributions other than Ubuntu. In this tutorial we see how to install it and used it on the latest version of Fedora.

In this tutorial you will learn:

  • How to install the snap package manager
  • How to search for packages in the snap store
  • How to install and update snap packages
  • How to list installed snap packages
  • How to create and manage snapshots of a package
  • How to remove snap packages
article-main
How to install and use snaps on Fedora

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distribution-independent
Software snapd
Other Root privileges to manage software
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

Installation

To use the Snappy package manager on Fedora, the first thing we need to do is to install the package containing the software. Luckily for us, it is a very easy thing to do, since it is available in the Fedora official repositories. We can perform the installation graphically or by using the dnf package manager from our beloved terminal emulator. Here is the command we want to run:

$ sudo dnf install snapd



The snap-confine and snapd-selinux package are installed as dependencies of snapd: the former contains the software used to apply confinement to snap applications, while the latter provides the policy which allows snapd to run properly under SELinux. As part of the installation, the snapd.socket is enabled by using systemd.

Searching for packages

The way we interact with snap packages is by using the snap application. One of the most basic action we need to perform is to find if a specific piece of software is available on the snap store. To accomplish this action we can use the “find” or “search” snap command (the latter is an alias for the former). Supposing we want to install the “gimp” snap package. To see if the application is available we can run:

$ snap find gimp

As you can see the command doesn’t require administrative privileges. It returns the following output:

Name                    Version  Publisher        Notes  Summary                                    
gimp                    2.10.28  snapcrafters     -      GNU Image Manipulation Program             
gutenprint-printer-app  1.0      openprinting✓    -      Gutenprint Printer Application             
photogimp               2.10.20  pedro.ermarinho  -      Patch para o GIMP                          
djpdf                   0.1.6    unrud            -      Create small, searchable PDFs from scanned documents                                                                                           
lazpaint                7.1.6    chronoscz        -      Image editor with raster and vector layers.

Information about the available packages which match our search criteria are returned:

  • The name of the package
  • The snap package version
  • The snap publisher
  • Eventual notes about the package
  • A brief package description

Installing snap packages

To install a snap package, all we have to do is to use the snap “install” command. Just as an example, suppose we want to install the gimp application we searched for in the previous step. Here is the command we would run:

$ sudo snap install gimp

By default, if no specified otherwise, packages are installed from the “stable” channel. Once we run the command above, we can track installation progress by reading the terminal output:

2022-03-29T14:25:15+02:00 INFO Waiting for automatic snapd restart...
gimp 2.10.28 from Snapcrafters installed



Recent versions of snaps support the “classic confinement” mode. When a snap package is installed in this mode, it is actually not confined, so it can access resources on the host system. If we want to install a package in this mode, we must run the “install” command with the --classic option.

File relative to snap packages and their dependencies are deployed on the system using the read-only SquashFS, in the form of loop devices, which are mounted in the corresponding directories under /var/lib/snapd. We can clearly see this by taking a look at the output of the lsblk command:

$ lsblk
NAME                   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0                    7:0    0  43.6M  1 loop /var/lib/snapd/snap/snapd/15177
loop1                    7:1    0  55.5M  1 loop /var/lib/snapd/snap/core18/2344
loop2                    7:2    0     4K  1 loop /var/lib/snapd/snap/bare/5
loop3                    7:3    0  65.2M  1 loop /var/lib/snapd/snap/gtk-common-themes/1519
loop4                    7:4    0 164.8M  1 loop /var/lib/snapd/snap/gnome-3-28-1804/161
loop5                    7:5    0 391.3M  1 loop /var/lib/snapd/snap/gimp/383

A loop block device exists for each snap package installed. In the case of the “gimp” snap, If we check the content of the /var/lib/snapd/snap/gimp/383 mountpoint (383 is the revision of the snap package – multiple revisions can be installed at the same time), we can see a whole filesystem tree which hosts the application files:

$ ls /var/lib/snapd/snap/gimp/383
bin data-dir etc lib meta sbin snap usr var

To be able to launch the application just how we would do after a system-native package installation, the /var/lib/snapd/snap/bin directory must be appended to our PATH. This should be done automatically as part of the snapd installation. We can verify it, by checking the value of the variable:

$ echo $PATH
/home/egdoc/.local/bin:/home/egdoc/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/var/lib/snapd/snap/bin

Updating a package

Multiple revisions of a snap package can coexist at the same time. We briefly saw how the currently installed revision of the gimp snap package is 383. The current active version is symlinked to /var/lib/snapd/snap/<package>/current. In the case of gimp:

$ ls -l /var/lib/snapd/snap/gimp
drwxr-xr-x. 11 root root 146 Nov 8 17:14 383
lrwxrwxrwx. 1 root root 3 Mar 29 14:27 current -> 383

To check if a new revision of a snap package is available, and update it, we can use the refresh command. In this case if we try to update the gimp package, we are notified that no updates are available:

$ sudo snap refresh gimp
snap "gimp" has no updates available

If we use the refresh command without specifying a package name as argument, the application will check for updates for all the snap packages installed on the system.

Listing installed snap packages

To get a report about the currently installed snap packages, all we have to do is to use the “list” command of the snap utility. Let’s see an example of the command in action:

$ snap list
Name               Version                     Rev    Tracking       Publisher     Notes
bare               1.0                         5      latest/stable  canonical✓    base
core18             20220309                    2344   latest/stable  canonical✓    base
gimp               2.10.28                     383    latest/stable  snapcrafters  -
gnome-3-28-1804    3.28.0-19-g98f9e67.98f9e67  161    latest/stable  canonical✓    -
gtk-common-themes  0.1-59-g7bca6ae             1519   latest/stable  canonical✓    -
snapd              2.54.4                      15177  latest/stable  canonical✓    snapd



We explicitly installed “gimp”, so all the other packages were installed as dependencies or as the “core” of the snap infrastructure. A tick after the name of the package publisher means that it has  been verified.

Creating and managing package snapshots

One nice feature of the snap package ecosystem is the ability to create snapshots of system, user and configuration data associated with a package. Snapshots are automatically created when a snap package is removed, but can be also created manually with the save command. To create a snapshot of the “gimp” package, for example, we would run:

$ sudo snap save gimp

If we don’t provide a package name as argument to the save command, snapshots for all the existing package are created. To get a list of the existing snapshots on the system, we can use the saved command:

$ sudo snap saved
Set  Snap             Age    Version                     Rev  Size    Notes
1    gimp             20.0m  2.10.28                     383   134kB  auto
3    gnome-3-28-1804  10.4m  3.28.0-19-g98f9e67.98f9e67  161    124B  -

In the output of the command we can see very useful information such as the snapshot id, and its age. To restore a snapshot we use the restore command, and we reference the snapshot we want to restore by its id. To restore the gimp snapshot we see in the output of the previous example, we would run:

$ sudo snap restore 1
Restored snapshot #1.

Finally, to manually remove an existing snapshot, we use the forget command. Here is what we would run to remove the gimp snapshot:

$ sudo snap forget 1
Snapshot #1 forgotten.

Removing snap packages

Intuitively, to remove a previously installed snap package, we must use the remove command. By default a package is removed with all its installed revisions. If we want to remove a specific revision of a package we have to pass it as argument to the --revision option. When specifying a revision, for it to be removed, it must not be the “active” one, so if you try to use the option when just one version of a snap package, the command will fail. Supposing we want to remove the “gimp” package we installed in this tutorial, for example, we would run:

$ sudo snap remove gimp

Or, in case more than one revision exist:

$ sudo snap remove gimp --revision 383



Snapshots of the snap package are not removed when we remove the package (a snapshot is actually created when the package is removed). To force their removal, we can pass the --purge option to the remove command. To remove “gimp” with all the associated snapshots, for example, we would run:

$ sudo snap remove --purge gimp

Conclusion

In this tutorial we learned how to use snap packages on Fedora. The snap packages ecosystem was originally developed by Canonical for Ubuntu, but then it become available also on other distributions. We learned how to search,install, update and uninstall snap packages on Fedora, and how to manage the snap package snapshots. Although snap packages work on Fedora, the default technology for self-contained applications used on the distribution is flatpak: if you want to know more on it, and learn how to use it, you can take a look at our tutorial on the subject.



Comments and Discussions
Linux Forum