Lesson 6.3: Snap Packages

Snap is Canonical's containerized application system. It provides automatic updates, rollback capabilities, and strict confinement, making it ideal for modern applications.

Why Snap? Snap packages include all dependencies, update automatically, and can be rolled back if updates cause problems. They work across multiple Linux distributions.

Understanding Snap

Snap uses a different packaging approach:

Snap Basics

Core Snap concepts and commands:

Installing Snap

Snap is pre-installed on Ubuntu. If not available:

$ sudo apt update $ sudo apt install snapd

Snap Store

The Snap Store is the main repository:

# Browse store in web browser https://snapcraft.io/store # Or use GNOME Software with Snap support

Basic Snap Commands

Essential Snap commands for daily use:

Search for Snaps

$ snap find firefox Name Version Publisher Notes Summary firefox 120.0-1 mozilla✓ Mozilla Firefox web browser firefox-beta 121.0b9 mozilla✓ Mozilla Firefox web browser vlc 3.0.18 videolan✓ VLC media player

Install Snaps

$ sudo snap install firefox firefox 120.0-1 from Canonical✓ installed # Install from specific channel $ sudo snap install firefox --beta # Install specific version $ sudo snap install firefox --channel=stable

Run Applications

# Run by snap name $ firefox # Run with specific command $ snap run firefox # Applications also appear in application menu

Managing Snap Packages

Update, remove, and manage your Snap installations:

List Installed Snaps

$ snap list Name Version Rev Tracking Publisher Notes firefox 120.0-1 5943 latest/stable mozilla✓ - vlc 3.0.18 3163 latest/stable videolan✓ - core20 20220831 1623 latest/stable canonical✓ base

Update Snaps

# Update all snaps $ sudo snap refresh # Update specific snap $ sudo snap refresh firefox # Check for updates $ snap refresh --list

Remove Snaps

$ sudo snap remove firefox firefox removed # Remove with configuration $ sudo snap remove firefox --purge

Snap Channels

Channels provide different versions of applications:

Available Channels

Channel Management

# Install from specific channel $ sudo snap install firefox --beta # Switch channels $ sudo snap refresh firefox --channel=beta # Track current channel $ snap info firefox channels: latest/stable: 120.0-1 2023-12-05 (5943) 82MB - latest/candidate: 120.0-1 2023-12-05 (5943) 82MB - latest/beta: 121.0b9 2023-12-08 (5945) 82MB - latest/edge: 121.0b10 2023-12-09 (5946) 82MB -

Snap Confinement

Snaps run with different confinement levels:

Confinement Types

Checking Confinement

$ snap list Name Version Rev Tracking Publisher Notes Confinement firefox 120.0-1 5943 latest/stable mozilla✓ - strict discord 0.0.27 623 latest/stable discord✓ - strict

Snap Services

Some snaps run background services:

Managing Services

# List services $ snap services Service Startup Current Notes lxd.daemon enabled active - docker.dockerd enabled active - # Start/stop services $ sudo snap stop docker $ sudo snap start docker # Restart services $ sudo snap restart docker

Snap Connections

Manage snap access to system resources:

Interface Connections

# Show connections $ snap connections firefox Interface Plug Slot Notes browser-support firefox:browser-support :browser-support - desktop firefox:desktop :desktop - home firefox:home :home - network firefox:network :network - # Connect interface $ sudo snap connect firefox:removable-media :removable-media # Disconnect interface $ sudo snap disconnect firefox:removable-media

Popular Snap Applications

Common applications available as snaps:

Web Browsers

Development Tools

Productivity

Snap Configuration

Customize Snap behavior:

User vs System Installation

# Install for current user $ snap install firefox --classic # Install system-wide (default) $ sudo snap install firefox # List user installations $ snap list --user

Snap Configuration

# Show snap configuration $ snap get firefox # Set configuration $ snap set firefox some.setting=value # Reset configuration $ snap unset firefox some.setting

Snap vs Other Package Systems

When to use Snap vs APT or Flatpak:

Use Snap For:

Use APT For:

Use Flatpak For:

Advanced Snap Features

Advanced Snap capabilities:

Version Rollback

# Show available versions $ snap revisions firefox Rev Tracking Version Notes 5943 latest/stable 120.0-1 - 5942 latest/stable 119.0-2 - 5941 latest/stable 118.0-2 - # Rollback to previous version $ sudo snap revert firefox --revision=5942 # Rollback to previous version $ sudo snap revert firefox

Snap Aliases

# Show aliases $ snap aliases Command Alias Notes firefox firefox - vlc vlc - # Create alias $ snap alias firefox web-browser # Remove alias $ snap unalias web-browser

Troubleshooting Snap

Common issues and solutions:

Installation Issues

# Check snap status $ snap version # Refresh snap store $ sudo snap refresh # Check system compatibility $ snap debug sandbox

Permission Issues

# Check missing connections $ snap connections firefox # Connect required interfaces $ sudo snap connect firefox:home :home # Run in devmode for testing $ sudo snap install some-app --devmode

Update Issues

# Check for blocked updates $ snap refresh --list # Force refresh $ sudo snap refresh --ignore-validation # Hold updates $ sudo snap refresh --hold firefox $ sudo snap refresh --unhold firefox

Practice Exercises

Exercise 1: Basic Snap Usage

  1. Search for a text editor
  2. Install the text editor
  3. Run the application
  4. List installed snaps
  5. Remove the text editor
Click for solution
$ snap find text editor $ sudo snap install notepad-plus $ notepad-plus $ snap list $ sudo snap remove notepad-plus

Exercise 2: Advanced Snap Management

  1. Install an application from beta channel
  2. Check application connections
  3. Connect additional interface
  4. Update all snaps
  5. Practice rollback functionality
Click for solution
$ sudo snap install firefox --beta $ snap connections firefox $ sudo snap connect firefox:removable-media :removable-media $ sudo snap refresh $ snap revisions firefox $ sudo snap revert firefox

What's Next?

Congratulations! You've now mastered all three major package management systems. Next, we'll apply all your knowledge in the capstone nginx project!

Continue to Module 7: Nginx Project

Key Takeaways

  • Snap provides containerized, auto-updating applications
  • Channels offer different release tracks
  • Confinement provides security through isolation
  • Rollback allows reverting to previous versions
  • Use Snap for modern applications needing auto-updates
  • Connections control system access for applications