How to Manage Snaps in Linux – Part 2

This is the second article in a two-part series about a beginner’s guide to snaps in Linux. It covers how to run snaps from the command-line interface, creates and use snap aliases, interacts with a snap’s services, and create and manage snapshots of a snap.

Run Apps from Snaps

A snap may provide a single application (or a group of applications) which you run from the graphical user interface or using commands. By default, all applications associated to a snap are installed under the /snap/bin/ directory on Debian based distributions and /var/lib/snapd/snap/bin/ for RHEL based distributions.

You can list the content of the snap directory using the ls command as shown.

$ ls /snap/bin/
OR
# ls /var/lib/snapd/snap/bin/

To run an app from the command-line, simply enter its absolute pathname, for example.

$ /snap/bin/mailspring
OR
# /var/lib/snapd/snap/bin/mailspring

To only type the application name without typing its full pathname, ensure that the /snap/bin/ or /var/lib/snapd/snap/bin/ is in your PATH environmental variable (it should be added by default).

You can verify the environmental variable by typing.

# echo $PATH
Check Environmental Variable
Check Environmental Variable

If the /snap/bin/ or /var/lib/snapd/snap/bin/ directory is in your PATH, you can run an app by just typing its name/command:

$ mailspring

To see the commands available beneath a snap, run the “snap info snap-name” command, and look at the command section as highlighted in the following screenshot.

# snap info mailspring
View Snap App Info
View Snap App Info

You can also find the absolute pathname of an application or command using the which command.

# which mailspring
Check Command Path
Check Command Path

Create and Using Snap Aliases

Snap also supports creating aliases for applications. A snap’s default (or standard) aliases have to undergo a public review process before they are enabled, but you create aliases for your local system.

You can create an alias for a snap using the alias command.

# snap alias mailspring mls
Create a Snap Alias
Create a Snap Alias

To list aliases for a snap, for example, mailspring, run the following command. From now on, you can use the alias to run the snap.

# snap aliases mailspring
List Alias for a Snap App
List Alias for a Snap App

To remove an alias for a snap, use the unalias command.

# snap unalias mls
Remove an Alias for a Snap
Remove an Alias for a Snap

Managing a Snap’s Services

For some snaps, the underlying functionality is exposed through applications that run as daemons or services, once the snap is installed, they are automatically started to run continuously in the background. Besides, the services are also enabled to automatically start at system boot. Importantly, a single snap may contain several applications and services that work together to provide the overall functionality of that snap.

You can check the services for a snap under the service section in the output of the “snap info snap-name” command. For example, for rocketchat-server.

# snap info rocketchat-server
View Services Available Under a Snap
View Services Available Under a Snap

You can cross-check the services for a snap using the services command. The command output shows a service, whether it is enabled to automatically start at system boot, and whether it is active or not.

# snap services rocketchat-server
List Services Under a Snap
List Services Under a Snap

To stop a service from running, for example, rocketchat, use the stop command. Note that this action is not recommended, as manually stopping a snap’s service(s) may cause the snap to malfunction.

# snap stop rocketchat-server

To start a service, for example, rocketchat use the start command.

# snap start rocketchat-server

To restart a service after making some custom changes to the snap application, use the restart command. Note that all services for a specified snap will be restarted, by default:

# snap start rocketchat-server

To enable a service to automatically start at system boot time, use the enable command.

# snap enable rocketchat-server

To prevent a service from automatically starting at the next system boot, use the disable command.

# snap disable rocketchat-server

To view the logs for a service, use the log command using the -f option, which allows you to watch the logs on the screen in real-time.

# snap logs rocketchat-server
OR
# snap logs -f rocketchat-server
View Logs of Snap App
View Logs of Snap App

Important: You can run the above service commands both on individual snap’s services and on all services for a named snap, depending on the parameter provided. This means you can use a more specific service name if a snap has many services.

Creating and Managing a Snap’s Snapshots

Snapd stores a copy of the user, system, and configuration data for one or more snaps. You can trigger this manually or set it up to work automatically. This way, you can backup the state of a snap, revert it to a previous state as well as restore a fresh snapd installation to a previously saved state.

To manually generate a snapshot, use the “snap save” command. To create a snapshot for mailspring, run the following command:

# snap save mailspring
Create a Snap App Snapshot
Create a Snap App Snapshot

If no snap name is specified, snapd will generate snapshots for all installed snaps (add the --no-wait option to run the process in the background to free up your terminal and allow you run other commands).

# snap save
Create Snap Apps Snapshot
Create Snap Apps Snapshot

To view the state of all snapshots, use the saved command. You can use the --id flag to show the state of a specific snapshot:

# snap saved
OR
# snap saved --id=2
View All Saved Snapshots of Snap Apps
View All Saved Snapshots of Snap Apps

You can verify the integrity of a snapshot using the check-snapshot command and the snapshot identifier (set ID):

# snap check-snapshot 2
Verify a Snapshot
Verify a Snapshot

To restore the current user, system and configuration data with the corresponding data from a particular snapshot, use the restore command and specify the snapshot set ID:

# snap restore 2

To delete a snapshot from your system, use the forget command. Data for all snaps are deleted by default, you can specify a snap to only delete its data.

# snap forget 2
OR
# snap forget 2  mailspring 

This brings us to the end of this two-part series about a beginner’s guide to using snaps in Linux. For more information, especially about setting system options to customize your snap environment and so much more, see the Snap documentation. As usual, your questions or comments are welcome via the feedback form below.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

4 thoughts on “How to Manage Snaps in Linux – Part 2”

  1. Having service(s) associated with snaps sounds like Windows; ugh. :(

    Having those services start at boot up sounds like Windows too.

    The alias feature is a semi +1.

    Reply
    • @Rob

      It’s the usual idea of applications running in the background as a daemon or services, just like managing (starting, enabling, etc.) services under systemd or any other init system. Snapd just manages its services (apps beneath a snap designed to run in the background as a daemon) independently from the main system and services manager.

      Reply
  2. The two articles make Snaps sound like the greatest thing since sliced bread. However, there isn’t one word about why it would be to my benefit to switching from the simplicity of distro repositories to the complex structure of Snaps. Just because something is new, does not mean that it is better.

    Reply
    • @dragonmouth

      There is a lot of word about why it would be to your benefit to switching from the simplicity of distro repositories to the complex structure of Snaps. As mentioned in the first article, snaps are easy to install across Linux distributions, they are also secure by default due to the way they run on a Linux system, and they support snapshots and many other useful features described in that article. Every package management system has its advantages and disadvantages, so you can give snap a try, maybe you will like it.

      Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.