In this guide, I’ll take you through the steps to install and use Snap on Rocky / AlmaLinux Linux server. For those new to snap terminology, snap comes from Snappy which is a package management and software deployment system from Canonical. It was originally designed for the Ubuntu phone operating system.

What is a snap?

snap :

  • is a squashFS filesystem containing your app code and a snap.yaml file containing specific metadata. It has a read-only file-system and, once installed, a writable area.
  • is self-contained. It bundles most of the libraries and runtimes it needs and can be updated and reverted without affecting the rest of the system.
  • is confined from the OS and other apps through security mechanisms, but can exchange content and functions with other snaps according to fine-grained policies controlled by the user and the OS defaults.
install snap centos 7

What is Snapd?

Snapd is a REST API daemon service that runs on your Linux system to manage snap packages (“snaps“). It interacts with the snap store and provides the command clientsnap used to interact with it. You must install snapd before you can start managing snaps on any Linux distribution.

Why use Snaps?

Snap packages any app for every Linux desktop, server, cloud or device. Snaps are faster to install, easier to create, safer to run, and they update automatically and transactionally so your app is always fresh and never broken. You can bring your own build infrastructure or use ours.

Install and Use Snapd on Rocky / AlmaLinux 9|8

Follow steps below to install Snapd on your system.

Add EPEL repository

#  Rocky / AlmaLinux 9
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

#  Rocky / AlmaLinux 8
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Install Snapd

sudo dnf -y install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

Wait for the installation to finish then enable snapd socket:

$ sudo systemctl enable --now snapd.socket
Created symlink from /etc/systemd/system/sockets.target.wants/snapd.socket to /usr/lib/systemd/system/snapd.socket.

Classic confinement requires snaps under /snap or symlink from /snap to /var/lib/snapd/snap. Create a symlink for it like below:

sudo ln -s /var/lib/snapd/snap /snap

Snapd is now ready for use. You interact with it using the snap command. See help page below:

$ snap --help
The snap command lets you install, configure, refresh and remove snaps.
Snaps are packages that work across many different Linux distributions,
enabling secure delivery and operation of the latest apps and utilities.

Usage: snap <command> [<options>...]

Commonly used commands can be classified as follows:

         Basics: find, info, install, remove, list
        ...more: refresh, revert, switch, disable, enable, create-cohort
        History: changes, tasks, abort, watch
        Daemons: services, start, stop, restart, logs
    Permissions: connections, interface, connect, disconnect
  Configuration: get, set, unset, wait
    App Aliases: alias, aliases, unalias, prefer
        Account: login, logout, whoami
      Snapshots: saved, save, check-snapshot, restore, forget
         Device: model, reboot, recovery
      ... Other: warnings, okay, known, ack, version
    Development: download, pack, run, try

For more information about a command, run 'snap help <command>'.
For a short summary of all commands, run 'snap help --all'.

Install Snap Applications on AlmaLinux / Rocky

We use snap command line tool to interact with snaps available on Snap Store.

Searching for a snap:

To search for Snaps, use

$ snap find <search terms>

This will query the store and list the results with their version number, developer names, and the description.

I’ll do an example for installation of Microsoft PowerShell automation and configuration management platform.

$ snap search powershell
Name                Version          Publisher              Notes    Summary
powershell          7.4.3            microsoft-powershell✓  classic  PowerShell for every system!
powershell-preview  7.5.0-preview.3  microsoft-powershell✓  classic  PowerShell for every system!
portal              1.2.3            zinokader              -        Quick and easy command-line file transfer utility from any computer to another.
v2rayx              0.4.5            shaonhuang             -        ✨✨V2ray GUI client with cross-platform desktop support powered by Electron⚛️, made especially for Linux / Windows / MacOS users.
ctfreak             1.15.0           jyp-software           -        IT task scheduler with concurrent and remote executions

Install snap by running:

sudo dnf install -y icu
sudo snap install powershell --classic

Wait for the download to finish, it should take short time to complete. Since the binary file is located under,/snap/bin/ we need to add this to the $PATHvariable.

$ sudo vim /etc/profile
export PATH="$PATH:/snap/bin/"

Source the file to get new PATH

source /etc/profile

Test by starting the pwshsession.

# pwsh 
PowerShell 7.4.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /root>

To list installed snaps:

$ snap list
Name        Version   Rev    Tracking       Publisher              Notes
core20      20240416  2318   latest/stable  canonical✓             base
powershell  7.4.3     269    latest/stable  microsoft-powershell✓  classic
snapd       2.63      21759  latest/stable  canonical✓             snapd

Manually update snaps by running snap refresh

$ sudo snap refresh powershell 
snap "powershell" has no updates available

Removing Snaps

To remove a snap, all you need to do is run.snap remove <snap name>  In our case just do:

$ sudo snap remove powershell
powershell removed

Check snap info:

Use the command snap info to check for more info about a snap package.

$ snap info powershell
name:      powershell
summary:   PowerShell for every system!
publisher: Microsoft PowerShell✓
store-url: https://snapcraft.io/powershell
contact:   https://github.com/powershell/powershell
license:   unset
description: |
  PowerShell is an automation and configuration management platform.
  It consists of a cross-platform (Windows, Linux, and macOS)
  command-line shell and associated scripting language.

  See https://docs.microsoft.com/powershell/scripting/powershell-support-lifecycle for support
  details.
commands:
  - powershell
snap-id:      JSNnoJl3EqkMuWoy5Dgq8PMqZ0uNcpie
tracking:     latest/stable
refresh-date: today at 17:55 UTC
channels:
  latest/stable:    7.4.3 2024-06-20 (269) 73MB classic
  latest/candidate: ↑
  latest/beta:      ↑
  latest/edge:      ↑
  lts/stable:       7.4.3 2024-06-20 (270) 73MB classic
  lts/candidate:    7.2.8 2022-12-13 (227) 71MB classic
  lts/beta:         7.2.8 2022-12-13 (227) 71MB classic
  lts/edge:         7.2.8 2022-12-13 (227) 71MB classic
installed:          7.4.3            (269) 73MB classic

Roll back to a previous version of an application

Use snap revert

$ sudo snap revert <snap name>

Conclusion

By now you should be able to install snaps the store, manually update them, remove them, check installed snaps and much more. The snap command line is designed to be as simple and memorisable as possible. It should become a second nature to you after using it just a couple of times.

LEAVE A REPLY

Please enter your comment!
Please enter your name here