Snap packages are a new way of packaging software for Linux distributions. They’re similar to the RPM and DEB formats, but they use Snaps instead of packages. This article will show you how to work with Snap packages on Linux. First, you need to install the snapd package. This package is used to manage snaps. Next, you need to create a directory where your snaps will be stored. For example, if your username is john and your computer’s hostname is example.com , you could create a directory called ~/snaps on your computer. To create a snap package, you first need to create a .snap file in the directory that you created earlier. The .snap file contains information about the snap package, such as its name and description. You can also include other files that are needed for the snap package to work correctly. Next, you need to add the .snap file to your Linux distribution’s repository. To do this, open a terminal window and type the following command: sudo add-apt-repository ppa:snappy/stable To add the .snap file from your ~/snaps directory, use this command: sudo add-apt-repository ppa:snappy/stable ~/snaps If you want to add the .snap file from another location on your computer, use this command: sudo add-apt-repository ppa:snappy/stable –add-source <path_to_file> After adding the repository information, type this command: sudo apt update The next step is to install the snapd daemon on your computer. To do this, type this command: sudo apt install snapd You can now start using snaps by typing this command: sudo snap install <package_name> For example: sudo snap install hello world If everything goes well, you should see a message like this one when you try to run the hello world program using snaps: ..

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 FlatPak 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:

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

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:

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 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:

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.

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:

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:

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

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:

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

Here’s the entire listing:

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.

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!

To do so, we type the following:

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:

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:

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:

Removing a snap Package

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

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