The Snap packages icon.
Ubuntu

When you install Linux software packages with snap, you can say goodbye to dependency hell and breaking other working applications. Snap packages were originally designed for Ubuntu, but they’re now available on a variety of Linux distributions.

What Are Snap Packages?

In the past, installing applications on Linux was a potentially frustrating experience. You’d install something only to find a particular library or other dependency was missing or outdated. You’d then hunt down the missing resource and install it, only to find another application depended on the version of the library you just replaced. Fix one, break one, repeat.

This has improved with better package management systems, like apt, dnf, and pacman. However, you still face a struggle if you need different versions of the same application installed. Or, if you use two applications that clash because they’re tied to specific—but different—versions of a library.

One solution to these problems is application packing and deployment systems. Snappy is one of the more popular of these. It’s based on a packaging and deployment system called Click, which harkens back to the Ubuntu Touch initiative. AppImage and FlatPack are others you might have encountered.

These systems encapsulate the application together with any dependencies and other requirements in a single compressed file. The application then runs in a sort of mini-container. It’s sandboxed and separated from other applications. The libraries and other resources the application is packaged with or requires are only available to it alone.

They aren’t installed in the traditional sense, so they don’t cause any problems with other applications that require different versions of the same resources. You can even install and run applications that need conflicting library versions because each application is in its own sandbox.

If they’re not installed in the usual way, though, how are they handled? Well, the single package file is downloaded, decompressed, and mounted as a SquashFSvirtual file system. It’s then presented to you as a virtual environment. All of this takes place behind the scenes. All you’ll know is you’ve installed an application, and, now, you have access to it.

Of course, because each package file must contain every resource the application needs, the package files can be large. It’s also easy to duplicate a resource you’d normally only install once, such as MySQL or Apache. If two different snap applications require the same resources, they each bring their own copy.

This is the trade-off for the simplicity of the install, and the removal of the resource-conflict headaches, though.

Installing snapd

Snappy was introduced with Ubuntu 16.04, so if you’re running that version or later, you’re already good to go. On our machine, Snappy was installed on Manjaro 18.04, but we had to install it on Fedora 31.

snap is both the name of the package files and the command you use to interact with them. Behind the scenes, the snapd daemon is also the name of the package you have to install if you don’t already have Snappy on your computer.

To install snapd on Fedora type the following command:

sudo dnf install snapd

The "sudo dnf install snapd" command in a terminal window.

If you need to install it on Manjaro, use these commands:

sudo pacman -Sy snapd
sudo systemctl enable --now snapd.socket

You can use the snap version command to see the version of the snap client, snapd daemon, and the software series number. The name and release of your Linux distribution and the kernel version will also be displayed for you.

Type the following:

snap version

The "snap version" command in a terminal window.

Installing snap Packages

It’s a pretty straightforward process to install a snap package. You can use snap to look for snap packages, and then install the one you want.

We type the following to look for and install the gimp image editor:

snap find gimp

The "snap find gimp" in a terminal window.

snap searches for matches to the search clue “gimp” and returns its findings. It’ll find anything that matches or mentions the search term.

To install one of the packages, we use the value from the Name column, as shown below:

sudo snap install gimp

The "sudo snap install gimp" command in a terminal window.

As it downloads, the percentage completed figure rises and a progress bar creeps across from the left of the terminal window. When the installation is complete, a message appears (as shown below) telling you the package was installed.

A "gimp 2.10.18 from Snapcrafters installed" message in a terminal window.

You can use the df command to check the capacity and usage of the different file systems configured on your Linux computer. If we pipe its output into the grep command and search for “gimp,” we isolate the entry for the package we just installed.

We type the following:

df | grep gimp

The "df | grep gimp" command in a terminal window.

This shows us the snap package was mounted as though it were a file system. The mount point is in the snap directory here: /snap/gimp/252. The “252” is the release number of this version of gimp.

RELATED: How to Use the grep Command on Linux

The file system is listed as: /dev/loop18. Loop device files are used to make regular files accessible as block devices. They’re typically used for mounting the file systems in disk images. In this case, they’re mounting the SquashFS filesystem within the snap package. The “18” means this is the 18th /dev/loop device file in use on this Linux computer.

We can use the df command to quickly check this. We’ll use the – t (type) option to limit the output to SquashFS file types only.

We type the following:

df -t squashfs

The "df -t squashfs" command in a terminal window.

The mounted SquashFS file systems are listed. A /dev/loop device file handles each one, and there are 18 of them.

SquashFS file systems llisted in a terminal window.

Each file system is mounted on a directory within the /snap directory. However, this doesn’t mean there are 18 different snap packages installed on this computer. This is an Ubuntu distribution, so some snap packages are installed right out of the box, and we’ve just installed another one.

Additionally, when you install snapd, it installs some core snap packages to handle the needs of other snap packages.

We can use the snap list command, as shown below, to list the installed snap packages:

snap list

A snap list in a terminal window.

The output was a little wide, so the end of the listings is shown below.

The end of the snap list output in a terminal window.

Here’s the entire listing:

Name                 Version                    Rev   Tracking  Publisher    Notes
core                 16-2.43.3                  8689  stable    canonical*   core
core18               20200124                   1668  stable    canonical*   base
gimp                 2.10.18                    252   stable    snapcrafters -
gnome-3-26-1604      3.26.0.20191114            98    stable/…  canonical*   -
gnome-3-28-1804      3.28.0-16-g27c9498.27c9498 116   stable    canonical*   -
gnome-calculator     3.34.1+git1.d34dc842       544   stable/…  canonical*   -
gnome-characters     v3.32.1+git3.b9120df       399   stable/…  canonical*   -
gnome-logs           3.34.0                     81    stable/…  canonical*   -
gnome-system-monitor 3.32.1-3-g0ea89b4922       127   stable/…  canonical*   -
gtk-common-themes    0.1-28-g1503258            1440  stable/…  canonical*   -

As you can see, there are 10 snap packages installed, not 18. However, these 10 packages have given rise to the 18 SquashFS file systems. The table columns are fairly self-explanatory, but here’s some clarification:

  • Name: The name of the snap package that was installed.
  • Version: The version number of the software in the snap package.
  • Rev: The revision number of the snap package.
  • Tracking: The channel this snap package monitors for updates. There are four:
    • Stable: The default channel. As its name states, this channel contains the most stable packages.
    • Candidate: This channel is less stable, but very close to it because it contains release candidate level software, which is code-complete. It goes through final testing before it’s moved to the stable channel.
    • Beta: This channel is late development-cycle quality, but it’s not guaranteed to be stable.
    • Edge: For early build testers. You shouldn’t use this channel for important work or on a production computer. Here be dragons!
  • Publisher: The individual, company, or organization that released the snap package. If it was a verified publisher (and your terminal window supports Unicode), you’ll see a green check mark beside the name of the publisher. If it can’t show a check mark, you’ll see an asterisk (*).
  • Notes: Any comments or additional information will appear here.

The snap Channels

You can use the info option to get a description of a snap package.

To do so, we type the following:

snap info gtk-common-themes

The "snap info gtk-common-themes" command in a terminal window.

We can see which channel the package is tracking, and the version of the software in the snap packages in each of the four channels. In most circumstances, you should stay on the stable channel.

A snap package checks four times per day to see whether a newer version of the software is available from the channel it’s watching or “tracking.”  If you want to change the channel a snap package tracks, you can use the refresh and --channel options.

To do so, we type the following:

sudo snap refresh gtk-common-themes --channel=beta

The "sudo snap refresh gtk-common-themes --channel=beta" command in a terminal window.

If a newer version of the software was available it would be installed, but that wasn’t the case here. However, the snap package is now tracking the beta channel. As soon as a new beta version is released, it’s automatically downloaded and upgraded.

You can use the --list option to check whether updates are available for any of the snap packages installed on your computer.

To do so, we type the following:

sudo snap refresh --list

The "sudo snap refresh --list" command in a terminal window.

You’ll be told if any of the channels the snap packages on your computer are tracking contain newer software versions.

If a newer version of the software is available, you can use the refresh option, as shown below, to manually force a refresh:

sudo snap refresh gtk-common-themes

The "sudo snap refresh gtk-common-themes" command in a terminal window.

Removing a snap Package

To uninstall a snap package, you can use the remove option, as shown below:

sudo snap remove gimp

The "sudo snap remove gimp" command in a terminal window.

The snap Cheat Sheet

Using snap packages is pretty simple, but we’ve compiled a list of some commands that will help you:

  • To search for a package: snap find package_name
  • To install a package: sudo snap install package_name
  • To see all installed packages: snap list
  • To get information about a single package: snap info package_name
  • To change the channel a package tracks for updates: sudo snap refresh package_name --channel=channel_name
  • To see whether updates are ready for any installed packages: sudo snap refresh --list
  • To manually update a package: sudo snap refresh package_name
  • To uninstall a package: sudo snap remove package_name
Dave McKay Dave McKay
Dave McKay first used computers when punched paper tape was in vogue, and he has been programming ever since. After over 25 years in the IT industry, he is now a full-time technology journalist. During his career, he has worked as a freelance programmer, manager of an international software development team, an IT services project manager, and, most recently, as a Data Protection Officer. Dave is a Linux evangelist and open source advocate.
Read Full Bio »