Set up Snapcraft

Snapcraft can be installed on all popular Linux distributions with systemd, macOS, and Windows.

Before you begin installation and setup, make sure your system meets the system requirements.

Install the main components

A working Snapcraft setup has two components – Snapcraft itself, and a build provider.

Install Snapcraft

If your Linux distribution has snapd installed, the easiest way to install Snapcraft is from the Snap Store:

snap install snapcraft --classic

Install a build provider

Snapcraft relies on a build provider to create an isolated build environment, like a sandbox. Inside this environment, software can be built and packaged as snaps without making potentially destructive changes to the host system.

Build provider

Description

Default on

LXD

Creates and manages Linux container images. It can operate inside VMs.

Snapcraft 7 and higher on Linux

Multipass

Creates and manages virtual machine (VM) build instances. It automates setup and teardown of cloud-style Ubuntu VMs. It can’t be used reliably on platforms that don’t support nested virtualization. In other words, it most likely won’t run inside another VM.

  • Snapcraft 6 on Linux

  • All versions on macOS and Windows

When you first run Snapcraft, it installs the default build provider for your host platform. If the default build provider isn’t suitable, you can install the alternative and then switch to it.

Install LXD

Install the LXD snap:

snap install lxd

LXD has special requirements from your local user account that Snapcraft can’t manage for you during its automatic setup. Add your user account to the lxd group so you can access the LXD daemon:

sudo usermod -a -G lxd $USER

Log out and back in to your local user account for the new group to take effect. Then, check that you’re a member of the group by running:

groups $USER

The list should contain lxd.

Finnally, initialize LXD with a lightweight configuration:

sudo lxd init --auto

If you need help troubleshooting your LXD installation, see How to install LXD in the LXD documentation.

Install Multipass

Install the Multipass snap:

snap install multipass

Tip

With core20 snaps and Multipass, the default virtual machine is assigned 2 CPUs and 2GB of RAM. To extend the hardware capacity, you can set the following environment variables to modify CPU and memory allocation, and improve performance:

export SNAPCRAFT_BUILD_ENVIRONMENT_CPU=8
export SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=16G

Install multiple instances of Snapcraft

If you’re installing Snapcraft as a snap, you can install multiple concurrent versions at the same time. Doing so could come in handy if you want to test new features in your snaps, before they arrive in a mainstream release.

First, enable parallel installs in snapd:

snap set system experimental.parallel-instances=true

List all the available versions of Snapcraft. For the version you’re interested in, take note of the value in the channel column.

snap info snapcraft

Install a new instance of Snapcraft with the instance key naming syntax, replacing <instance> with whichever name is appropriate for the instance, and <channel> with the target channel and track:

snap install snapcraft_<instance> <channel> --classic

For example, you could install the very latest official releases with:

snap install snapcraft_edge latest/edge --classic

Whenever you want to run this parallel version of Snapcraft, invoke the instance name of the command – in this example, snapcraft_edge.