Ubuntu ships snap alongside apt. Snaps are self-contained packages that bundle their own dependencies, update automatically and run in a confinement sandbox. On servers they’re useful for a few tools, such as Certbot, LXD and some CLIs. Many admins also prefer to turn them off. Here’s how to work with snaps either way.

Basic commands

snap list                      # installed snaps
snap find nextcloud            # search the Snap Store
snap info certbot              # description, channels, versions
sudo snap install certbot --classic
sudo snap remove certbot

--classic gives a snap full system access, without strict confinement. Tools that need to touch the whole system, like Certbot, editors and compilers, use classic confinement.

Channels: choose stability

Snaps are published in channels, given as track/risk: latest/stable, latest/candidate, latest/beta and latest/edge. Some snaps have version tracks, such as lxd 5.21/stable.

sudo snap install lxd --channel=5.21/stable
sudo snap refresh lxd --channel=latest/stable    # switch channel

Stay on stable on servers.

Updates (refreshes)

Snaps update themselves automatically, up to four times a day by default. That’s convenient for security fixes, but it can restart services unexpectedly. Control it:

snap refresh --list                         # pending updates
sudo snap refresh                           # update now
sudo snap set system refresh.timer=sat,03:00-05:00   # only Saturdays, 3–5am
sudo snap refresh --hold=72h certbot        # postpone one snap
sudo snap refresh --hold                    # hold all snaps indefinitely (snapd 2.58+)

Roll back to the previous revision if an update breaks something:

sudo snap revert certbot

Disk usage: old revisions

By default snapd keeps 3 revisions of each snap (current plus 2 old). Each one is a mounted squashfs image under /var/lib/snapd/snaps, and that adds up on small disks.

du -sh /var/lib/snapd/snaps
sudo snap set system refresh.retain=2      # keep only current + 1

Remove the disabled old revisions now:

snap list --all | awk '/disabled/{print $1, $3}' |
  while read -r name rev; do sudo snap remove "$name" --revision="$rev"; done

Each snap also appears as a /dev/loop* device in df and lsblk output. That’s normal and harmless.

Services in snaps

snap services
sudo snap restart lxd
sudo snap logs lxd -n 100

Snap service files live under /etc/systemd/system/snap.*, and journald collects their logs.

Snap vs apt on servers

apt (deb) snap
Updates When you run upgrades (or via unattended-upgrades) Automatic, with a configurable window
Dependencies Shared system libraries Bundled
Disk use Smaller Larger, with several revisions kept
Config locations Standard /etc Often /var/snap/<name>/
Startup speed Fast Slightly slower (mounting squashfs)
Confinement None AppArmor sandbox (unless classic)

Rule of thumb: on servers, prefer apt packages or official vendor repositories. Use snaps where they’re the officially recommended route (LXD, Certbot’s preferred install method) or where no good deb exists.

Watch for snap-only packages. On Ubuntu, apt install chromium-browser (and on some releases firefox) actually installs the snap.

Remove snapd completely

If you don’t use any snaps (check snap list first):

# remove all snaps, apps first, then base snaps (core*, snapd) last
snap list
sudo snap remove --purge lxd
sudo snap remove --purge core22
sudo snap remove --purge snapd

sudo apt purge snapd
sudo rm -rf /var/cache/snapd /snap ~/snap

# stop apt from reinstalling it as a dependency
sudo tee /etc/apt/preferences.d/no-snap.pref > /dev/null <<'EOF'
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF

This frees disk space and memory (snapd itself runs as a daemon), and removes the loop devices. It’s reversible: drop the preference file and run sudo apt install snapd.

Install Certbot without snap

If you’ve removed snapd, Certbot is available from apt (sudo apt install certbot python3-certbot-nginx). The distribution version is a bit older but fully functional. See Let’s Encrypt with Nginx.

Quick reference

Task Command
List snap list
Install sudo snap install name [--classic]
Update all sudo snap refresh
Refresh window sudo snap set system refresh.timer=sat,03:00-05:00
Hold updates sudo snap refresh --hold=72h name
Roll back sudo snap revert name
Keep fewer revisions sudo snap set system refresh.retain=2
Remove sudo snap remove --purge name

Related: dpkg and apt commands.

  • Ubuntu
  • Linux
  • Packages