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:

sudo snap install snapcraft --classic

Install a build provider

Snapcraft is compatible with two build providers – Multipass and LXD. It relies on a build provider to host 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.

For core22 and higher, LXD is the default provider on Linux, and Multipass is the default on macOS and Windows.

For core20, Multipass is the default provider on all platforms.

Choose a build provider

Before proceeding, you must choose a build provider.

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. For instance, it most likely won’t itself run inside a VM.

LXD creates and manages Linux container images. It can operate inside VMs.

If the default build provider isn’t fit for your snap, you can switch between them.

Install Multipass

If Multipass isn’t installed, on first run Snapcraft will ask you’d like to automatically install and configure it. If you agree, it will walk you through installation.

To install Multipass on its own, run:

sudo 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 LXD

To install LXD:

  1. Install the app:

    sudo snap install lxd
    
  2. Add your user account to the lxd group so you can access the tool’s resources:

    sudo usermod -a -G lxd $USER
    
  3. Log out and back in to your account for the new group to become active. Then, check that you’re a member of the group by running:

    groups $USER
    

    lxd should be present in the output.

  4. Finally, initialise LXD with a lightweight, default configuration:

    lxd init --minimal
    

See How to install LXD in the LXD documentation for further installation options and troubleshooting.

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.

To install another instance of Snapcraft:

  1. Enable parallel installs in snapd:

    sudo snap set system experimental.parallel-instances=true
    
  2. List all the available versions of Snapcraft. For the version you’re interested in, take note of the value in the channel column.

    sudo snap info snapcraft
    
  3. Install Snapcraft using the instance key naming syntax. Replace edge with whichever name is appropriate for the instance, and latest/edge with the target channel and track:

    sudo 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.