The standard way to get a clean build environment using
snapcraft is to use the
lxd integration. If you don’t have lxd installed, it can be installed via snap:
sudo snap install lxd
sudo adduser <your-user> lxd
You’ll need to log-out and back-in to get the lxd group assignment to take-root in your session.
Finally you need to initialise lxd:
sudo lxd --init
It has sane defaults so it’s ok to just press enter at each option unless you know you need a different setting.
Now you can use either:
The first option creates a new container for every attempted build, while the second option creates one container which persists and is reused for subsequent builds run while the
SNAPCRAFT_CONTAINER_BUILDS=1 environment variable is visible. If you want to, you may
SNAPCRAFT_CONTAINER_BUILDS variable into future sessions automatically via editing your
$HOME/.bash_profile and adding a line:
If you have done that and restarted your session you can revert to using
snapcraft without specifying the variable each time. While the export is set in your profile each of the following commands will work as-is using a persistent lxd container:
snapcraft clean -s pull
snapcraft clean with no arguments will delete the container used for the snap package build. Snapcraft will use a different container for each package name as specified in the
snapcraft.yaml, so as to allow working on multiple packages without trampling on the persistent container used for each.