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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

6 Comments

Leave a Reply
  1. I have just installed snap to install projectlibre as the normal deb is now not updated in favour of the snap.

    So now I have to search on the web to find how to run it from the command line. It feels like going back 20 years.

    Reply
  2. Is this use of memory normal for snap apps?

    ~$ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            7.8G     0  7.8G   0% /dev
    tmpfs           1.6G  1.6M  1.6G   1% /run
    /dev/sda4        39G   12G   25G  33% /
    tmpfs           7.8G   92M  7.7G   2% /dev/shm
    tmpfs           5.0M  4.0K  5.0M   1% /run/lock
    tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
    /dev/loop2       78M   78M     0 100% /snap/knowte/2
    /dev/loop1      163M  163M     0 100% /snap/gnome-3-28-1804/145
    /dev/loop3       56M   56M     0 100% /snap/core18/1885
    /dev/loop6      384K  384K     0 100% /snap/bpytop/147
    /dev/loop4       61M   61M     0 100% /snap/core20/634
    /dev/loop5       98M   98M     0 100% /snap/core/10185
    /dev/loop7       78M   78M     0 100% /snap/knowte/3
    /dev/loop8       63M   63M     0 100% /snap/gtk-common-themes/1506
    /dev/loop9       57M   57M     0 100% /snap/bitwarden/31
    /dev/loop10     162M  162M     0 100% /snap/gnome-3-28-1804/128
    /dev/loop11      76M   76M     0 100% /snap/vitomu/2
    /dev/loop12      98M   98M     0 100% /snap/core/10126
    /dev/sda5       499G  108M  498G   1% /files
    /dev/sda3        39G   49M   37G   1% /tmp
    /dev/sda1       288G  129G  144G  48% /home
    /dev/sda7        33G   49M   31G   1% /other
    tmpfs           1.6G   20K  1.6G   1% /run/user/1000
    /dev/loop13     384K  384K     0 100% /snap/bpytop/152
    /dev/loop14      56M   56M     0 100% /snap/core18/1932
    
    Reply
  3. 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
  4. 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...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.