The Snap packages has been around since Ubuntu 16.04. Just like the long-known deb format has its own commands to perform operations on .deb packages, there are commands dedicated to managing Snap packages as well. In this article we will learn how to perform basic management operations on Snap packages.
Tip: Meanwhile, check out some of the best games available in the Snap store.
Before proceeding towards learning the practical usage, it’s important that you are theoretically clear about the Snap packaging system.
The aim of this packaging system is to make package installation and maintenance easier and safer. For example, unlike the existing system, where it’s on you to resolve all version-related conflicts of dependencies for a software being installed, Snaps allow developers to put in everything their software depends on in the package itself, effectively making them self-contained and independent of the system on which they are being installed.
With snaps, software updates are also automatically in the background, which makes it more convenient for the user.
Good to know: Interested in learning more about Snap? You can use Snapcraft to create distribution-agnostic Snap packages in Linux.
Snap Package Management Commands
Before jumping to the standard Snap commands, you first need to install the snappy command line tools on your system, if they haven’t been already, by following this command:
sudo apt install snapd
Install Snap Packages
The following is the command for installing Snap packages:
sudo snap install [packagename]
For example, here is the command I used to install the “htop” application:
sudo snap install htop
List All Installed Snaps
To display a summary of all the installed Snap packages on your system, run the “Snap” command with
Update a Snap
To update a particular snap to a more recent or latest version, use the
refresh sub-command followed by the package name. For example, if in the future I’ll have to update the “htop” tool, I’ll run the following command:
sudo snap refresh htop
Find Snap Packages
find sub-command is available for this operation. It queries for available packages. Here’s an example:
You can also search for a particular Snap, such as this example:
sudo snap find htop
Remove a Snap
Similar to the way you install a Snap, you can easily remove a Snap package from your system – the sub-command to use in this case is
remove. In this example I removed the “htop” tool:
sudo snap remove htop
Disabling a Snap
It is also possible to “disable” a snap package in your computer. This will not remove the program’s files in your system but it will make it inaccessible to the rest of your system. This can be helpful if you want to remove a package from your PATH but you still intend to use it later.
To disable the htop snap package, run the following command:
sudo snap disable htop
You can bring back a snap package from its hibernation by using
sudo snap enable htop
Good to know: While Canonical developed Snap packages for Ubuntu, it is also available for other Linux distributions, like Arch Linux. Find out how you can install Snap packages in Arch.
Debugging Snap Packages
Aside from being a capable package manager, snap also provides you with powerful debugging commands and flags. You can use these to either diagnose problems in your packages or explore the in-development versions of your favorite programs.
To do the latter, you can append either the
--beta flags to the end of your install command:
sudo snap install --beta htop
Refreshing the Settings of an Existing Snap
refresh command can also change the properties of the snaps that you have already installed in your system. This is helpful if you want to switch your development version package back to a regular stable one:
sudo snap refresh --stable htop
It also supports a number additional flags that allows you to change the security policy of a program. For example, you can use the
--jailmode flag to strictly isolate a package from the rest of your system:
sudo snap refresh --jailmode htop
Tip: Security does not stop with isolating individual packages in your system. Learn how you can protect your data online by installing privacy-focused extensions in Chrome.
Rolling Back Snap Packages
Similar to transactional package managers, snap supports the ability to roll back updates on a per-package basis. This makes it incredibly easy to undo and prevent any misbehaving package from breaking your system.
To roll back a single snap package, run the following command:
sudo snap revert htop
Just like the
refresh subcommand, you can also use the same flags in revert to lock down a misbehaving application:
sudo snap revert --jailmode htop
FYI: Flatpak is similar to Snap. Find out the differences between Flatpak and Snap and which one you should choose.
Frequently Asked Questions
Will snap overwrite the packages that I installed through apt?
No. Snap will not change any program and file that you currently have in your system. However, one of the issues with snap is that Ubuntu will always load the snap package first before any apt program. This can be a problem if you have configured an apt program before installing its snap version.
Can I remove the file access of a snap package without disabling it?
Yes. You can do this by disconnecting the file access “plug” from your snap package. First, run:
sudo snap interfaces snap-package. Next, find the plug that you want to disable and run:
sudo snap disconnect snap-package:plug.
Is it possible to know the configuration options of a snap package?
Yes. You can check all the available configuration options for a snap package though the
get subcommand. For example, you can run
sudo snap get htop to get the configuration options for htop.
Image credit: Lukas via Unsplash. All alterations and screenshots by Ramces Red.
Our latest tutorials delivered straight to your inbox