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:
- Containerization: Apps run in isolated containers
- Auto-updates: Applications update automatically
- Rollback: Revert to previous versions
- Confinement: Apps have limited system access
- Channels: Different release tracks (stable, beta, etc.)
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
- stable: Recommended for most users
- candidate: Pre-release testing
- beta: Feature testing
- edge: Latest development version
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
- Strict: Full sandboxing, minimal system access
- Classic: Traditional system access (less secure)
- Devmode: Development mode with relaxed restrictions
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
- Firefox:
firefox
- Chromium:
chromium
- Brave:
brave
- Vivaldi:
vivaldi
Development Tools
- VS Code:
code
- IntelliJ:
intellij-idea-ultimate
- PyCharm:
pycharm-professional
- Docker:
docker
Productivity
- LibreOffice:
libreoffice
- GIMP:
gimp
- Inkscape:
inkscape
- Discord:
discord
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:
- Auto-updates: Applications that should update automatically
- Rollback: When you need version control
- Latest Versions: Getting newest software quickly
- Canonical Apps: Official Ubuntu applications
- Server Software: Modern server applications
Use APT For:
- System Integration: Deep system integration needed
- Libraries: Development libraries and headers
- Command-Line: Terminal applications
- Security Tools: System-level security software
Use Flatpak For:
- Universal Apps: Cross-distribution compatibility
- GUI Applications: Modern desktop applications
- Development: Testing in clean environments
- Third-Party: Non-Canonical applications
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
- Search for a text editor
- Install the text editor
- Run the application
- List installed snaps
- 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
- Install an application from beta channel
- Check application connections
- Connect additional interface
- Update all snaps
- 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!
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