Cannot install snapcraft on wsl 2 ubuntu 20.04

Hello!

I have a fresh installation on WSL 2 with Ubuntu 20.04. When i try to install snapcraft i get:

sudo apt install snapcraft
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  snapcraft
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 7680 B of archives.
After this operation, 55.3 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 snapcraft all 3.0ubuntu1 [7680 B]
Fetched 7680 B in 0s (27.6 kB/s)
Preconfiguring packages ...
Selecting previously unselected package snapcraft.
(Reading database ... 32157 files and directories currently installed.)
Preparing to unpack .../snapcraft_3.0ubuntu1_all.deb ...
=> Installing the Snapcraft snap
==> Checking connectivity with the snap store

After a few minutes i receive:

And then:

===> Aborting at user request
dpkg: error processing archive /var/cache/apt/archives/snapcraft_3.0ubuntu1_all.deb (--unpack):
 new snapcraft package pre-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/snapcraft_3.0ubuntu1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
W: Operation was interrupted before it could finish

Also, snap info snapcraft does nothing, it just hangs.

Can snapcraft be installed in WSL 2 with Ubuntu?

Solved it by finding the git repository: DamionGans/ubuntu-wsl2-systemd-script: Script to enable systemd support on current Ubuntu WSL2 images [Unsupported, no longer updated] (github.com)
on Running Snaps on WSL2 (Insiders only for now) - snapd - snapcraft.io

Also i needed to reinstall snapd ( see Bug #1826662 “Can’t install any snaps: too early for operation, …” : Bugs : snapd (launchpad.net)):

1. $ sudo service snapd stop
2. $ sudo apt purge snapd
3. $ sudo apt install snapd

EDIT
I have tried to built the snap in destructive mode, otherwise i get a VM error:

Launching a VM.
launch failed: CPU does not support KVM extensions.
An error occurred with the instance when trying to launch with 'multipass': returned exit code 2.
Ensure that 'multipass' is setup correctly and try again.

But also in destructive-mode i get an error:

...
Get:1 libpng16-16_1.6.37-2_amd64.deb [179 kB]
Fetched 179 kB in 0s (0 B/s)
Sorry, an error occurred in Snapcraft:
[Errno 1] Operation not permitted
We would appreciate it if you anonymously reported this issue.
1 Like

WSL2 isn’t an ideal environment for working with Snapcraft. It’s lacking a lot of functionality that would be expected from a standard installation of Linux and ultimately I’d say it’d be better to try another tool.

Multipass provides a WSL2 like experience but should run snapcraft just fine (seeing as your CPU doesn’t support nested virtualisation, I’d suggest using the LXD backend with it rather than destructive mode). If you’re using Windows 10 pro it’d work fine, alternatively it works with Windows 10 home with Virtualbox installed. Unfortunately it doesn’t work with Windows 10 home with WSL2 running just yet, if you’re in this camp, I’d suggest just using VBox natively.

Though if you do use multipass you probably want to have more disk space than the default VM would have, so be sure to create a VM with sufficient resources in advance, it’s something like multipass launch -d 50G -m 16G -c 8 for -disk -memory and -cpu’s