Working with Snap Packages
Snap packages are self-contained application bundles that include all their dependencies. Unlike APT packages, snaps do not depend on shared system libraries — each snap ships its own copy. This makes snaps more portable and easier to update, but they are also larger on disk and slower to start than equivalent APT packages.
How snap differs from apt
| Aspect | APT | Snap |
|---|---|---|
| Dependencies | Shared system libraries | Bundled inside the snap |
| Updates | Manual: apt upgrade | Automatic (background daily) |
| Rollback | Not built-in | Built-in: snap revert |
| Sandbox | No isolation | AppArmor-based confinement |
| Install time | Fast | Slower (larger downloads) |
| Startup time | Normal | Slower (mount squashfs) |
| Multiple versions | Manual pinning | Channels (stable/edge/etc.) |
Essential snap commands
# Search for a snap
snap find "vs code"
snap find lxd --narrow
# See detailed info about a snap before installing
snap info code
# Install a snap (default: stable channel)
sudo snap install lxd
sudo snap install code --classic # --classic: unrestricted access to system
# List all installed snaps with their version and channel
snap list
# Update a specific snap
sudo snap refresh lxd
# Update all snaps
sudo snap refresh
# See pending updates
snap refresh --list
# Remove a snap
sudo snap remove lxd
# Remove and keep no revision history (frees disk immediately)
sudo snap remove --purge lxd
snap list output
Name Version Rev Tracking Publisher Notes
core22 20240111 1122 latest/stable canonical base
lxd 5.21.1-c5ae129 27428 5.21/stable canonical -
microk8s v1.30.0 6979 1.30/stable canonical classic
snapd 2.62.1 21185 latest/stable canonical snapd
Snap channels
Every snap has multiple release tracks and stability levels. The channel format is track/risk — for example 1.30/stable for MicroK8s 1.30 stable.
| Risk level | Meaning | Use for |
|---|---|---|
stable | Production release, fully tested | Servers, production use |
candidate | Release candidate, near-stable | Pre-production testing |
beta | Feature-complete, may have bugs | Lab/dev environments |
edge | Latest build from main branch | Development/testing only |
# Install from a specific channel
sudo snap install microk8s --channel=1.30/stable
# Switch a snap to a different channel
sudo snap refresh lxd --channel=5.21/stable
# See all available channels for a snap
snap info lxd | grep "channels:"
Snap confinement levels
# See the confinement level of a snap
snap info lxd | grep confinement
# Install with strict confinement (default, most secure)
sudo snap install lxd
# Install with classic confinement (full system access, less secure)
# Required for tools like VS Code, kubectl, helm
sudo snap install code --classic
# Check what permissions a snap has
snap connections lxd
Managing snap services
Some snaps install background services. These are managed via snap services, not systemctl.
# List services provided by a snap
snap services lxd
# Start/stop/restart a snap service
sudo snap start lxd
sudo snap stop lxd.daemon
sudo snap restart lxd
# Enable a service to start on boot
sudo snap enable lxd
# View snap service logs
sudo snap logs lxd
sudo snap logs lxd -n 50 # Last 50 lines
Snap storage and cleanup
By default, snap keeps the two most recent revisions of each installed snap. When a snap updates, the old revision stays on disk as a fallback. This can accumulate several hundred megabytes.
# Check snap disk usage
df -h /var/snap
du -sh /var/lib/snapd/snaps/
# See all revisions installed for each snap
snap list --all
# Remove old revisions manually (keep only the current one)
# Create a script for this:
snap list --all | awk '/disabled/{print $1, $3}' | while read name rev; do
sudo snap remove "$name" --revision="$rev"
done
# Set how many old revisions to keep (1 = only current, minimum for rollback)
sudo snap set system refresh.retain=2 # Default is 2
Conclusion
Snaps are the right choice when the vendor only provides a snap, when you need an isolated environment, or when you need easy channel-based version management (like different Kubernetes versions side-by-side with MicroK8s). Prefer APT for everything available there — APT packages start faster, use shared libraries, and integrate more cleanly with the system. Clean up old snap revisions periodically to recover disk space, and use snap revert to roll back a bad update rather than reinstalling.
FAQ
Is Working with Snap Packages important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support