TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Linux

An Introduction to the Snap Universal Package Manager

Snap packages combine the app and any dependencies it may have in a single, compressed file.
Dec 7th, 2024 7:00am by
Featued image for: An Introduction to the Snap Universal Package Manager

Package managers simplify the process of installing and managing applications on the Linux operating system. Prior to package managers (going way back to the late 1990s), most Linux apps had to be installed from source. Sometimes, that process was simple, but other times, you could wind up in a dependency hell where app X depended on library Y, which depended on build utility Z. Those dependency trees could get very complex, such that installing a single application would lead you to install any number of apps and have to resolve all of the dependency of those apps.

It could be very challenging. I remember several occasions where I had to give up because I’d wind up in a dependency loop (where an app depended on a piece of software that couldn’t be installed because one or more dependencies wouldn’t install).

Thankfully, those days are over, and installing applications on Linux has become incredibly easy. We have apt (Debian/Ubuntu), dnf (Red Hat/Fedroa), pacman, zypper (Arch) and other package managers that not only install the applications but take care of the dependencies.

Those package managers haven’t resolved all of the issues. For example, if a developer wants to create an app for Linux, they have to consider a number of variables:

  • What distribution
  • What package manager
  • What desktop environment

Given how many distributions, package managers and desktop environments there are, the number of combinations can quickly become overwhelming, and no developer wants to have to release an app that will work for:

  • Ubuntu > apt > GNOME
  • Ubuntu > apt > KDE Plasma
  • Fedora > dnf > GNOME
  • Fedora > dnf > Xfce

You get the idea.

This is one of the reasons why universal package managers were created. Instead of having to produce a version of an app that will work with all iterations of Linux, they only have to release a single package that works with one of the universal package managers.

One of those universal package managers is Snap.

Snap was created by Canonical to help ease the burden of designers and make it easier for Ubuntu (and Ubuntu-based distributions) to gain access to a wealth of applications. In the end, what Canonical created was a simple solution for a very complex problem.

How Snap Packages Work

Snap packages combine the app and any dependencies it may have in a single, compressed file. Once installed, the application runs in a pseudo-container that is sandboxed from other applications, so the libraries and dependencies for the application are not available to other applications on the system.

Although some argue that Snap packages don’t open as quickly as native apps do, the difference (in most cases) is negligible. If you are concerned about speed, the security and simplicity benefits should top that issue. Personally, I’d rather sacrifice a bit of speed for the additional security of sandboxing.

When a Snap package is downloaded, it is then decompressed, mounted as a SquashFSvirtual file system and made available within a virtual environment. That process is the reason why Snap packages take slightly more time to open than those developed for the native environment. Snap depends on a daemon running in the background, which is snapd.

Speaking of which…

As with the default package managers (such as apt, dnf and pacman), Snap packages can be managed from the command line or a GUI. For example, on Ubuntu, Snap package support is baked into GNOME Software, so you don’t have to use the command line interface to install, refresh or delete an application.

Now that you understand what a Snap package is, let me walk you through how Snap works.

Installing Snap

Let’s say you’re using a Linux distribution that doesn’t ship with Snap installed by default. Fortunately, it’s possible to install Snap on Ubuntu, Fedora and Arch-based distributions. Here are the commands for installing Snap on each:

  • Ubuntu — sudo apt-get install snapd -y
  • Fedora — sudo dnf install snapd -y
  • Arch — sudo pacman -Sy snapd

Once installed, you have to start the Snap daemon and make sure it’s set to start at boot. To do this, run the following command:

sudo systemctl enable --now snapd

The Snap daemon should now be running and ready to go.

Managing Apps With Snap

Let me show you how easy it is to manage applications with Snap. Fortunately, the process of using Snap is the same, no matter what distribution you use.

Before you install an app, you might want to search for it first. For instance, we can run a search for Spotify with the command:

snap find spotify

The results may include several different apps, including:

spotify        1.2.50.335.g5e2860a8  spotify✓                -      Music for everyone
spotify-qt     v3.11                 kraxarn                 -      Lightweight Spotify client using Qt

Most likely, the app you’re looking for will be the first listed. If you look closely to these two instances, you’ll see that only one was released by Spotify itself (the first one listed). I highly recommend that you only install Snap packages that are verified because, well, you never know what could be included in those packages.

The thing is (and this is important) Snap packages aren’t reviewed because there’s no way of reviewing proprietary software (such as Spotify and Slack). Keep in mind, however, that Snap apps are sandboxed, which does remove some of the security concerns for those apps that aren’t from verified sources. To be safe, I always go with the verified app.

You could then install Spotify with the command:

sudo snap install spotify

You will be asked to verify the installation. Once the app is installed, you should find it in your desktop menu. If it’s not there, log out and log back in, and it will appear.

Typically, Snap apps are automatically refreshed (updated), but you can do it manually with the command:

sudo snap refresh

If all Snaps are currently up to date, you’ll see the following in the output:

All snaps up to date.

The above command updates all installed Snaps. If you want to update a single Snap, the command would be:

sudo snap refresh APP

Where APP is the name of the app you want to update.

You can also remove a Snap app with the command:

sudo snap remove APP

Where APP is the name of the app you want to remove.

If you want to view all of the Snap packages installed on your system, issue the command:

snap list

The results will list the name, version, revision number, tracking, publisher and any notes. Here’s a typical listing in the output:

slack 4.41.104 177 latest/stable  slack✓   -

As a side note, if you want to select a Snap package for installation from your distribution’s app store, you can select the Snap version you want to install from within the listing (Figure 1).

 

Screenshot

Figure 1: Not every app found in the Ubuntu Software app will include both Snap and DEB versions.

And that’s all there is to using Snap packages. If your Linux distribution of choice includes Snap support, you now know how to manage those applications from the command line or to easily install them with the GUI.

Happy snapping!

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.