WSL: WSL2- Ubuntu 20.04 Snap store doesn't work due to systemd dependency
I just reinstalled ubuntu on WSL2 from scratch in order to upgrade to 20.04 with a clean slate. The main issue I’ve noticed has to do with a lot of packages moving to snap rather than being maintained on apt, which is how I imagine most people here install their packages.
In fact it seems like Ubuntu 20.04 LTS replaced the ubuntu software with snapcraft entirely. So it’s obvious snap is becoming the ‘default’ of the distro.
The issue is that snap doesn’t currently seem to work on wsl2 due to it’s reliance on systemd. If I understand it correctly, the snapd service should be running in the background for it to work, which snapd already comes preinstalled, however snapd can’t start due to WSL2 not having systemd.
So if I run the command snap find node for example, it gives me the following error message:
error: cannot communicate with server: Post http://localhost/v2/snaps/hello-world: dial unix /run/snapd.socket: connect: no such file or directory
Running the command sudo service snapd start simply responds with:
snapd: unrecognized service
However snapd is already installed.
Is there any plan to get this working in the future, or is it something that is in progress?
In my development flow, I like to use the chromium-browser on WSL2 with the X410 server in order to test my web apps in both Windows and Linux browsers, since they can reveal some bugs, like say, when uploading csv files files from a Windows browser, React can’t really tell since Windows changes the MIME Type of the file, whereas Linux and Mac keep it the same and so it’s easy to handle.
Now I can’t really use chromium though, since I can’t install it without snap anymore.
EDIT: After several hours of trying to fix it I came across several other issues from about 8-10 months ago, with the most popular solution being this, which seems to make some changed to PIDs to make it work, but it just seems so hacky, and it’s not a permanent solution, as a restart will remove it.
- Windows Version: 10.0.19613.1000
- Ubuntu 20.04 WSL2
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 320
- Comments: 164
just try:
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
snap version
Here is the link to the scripted version of the workaround @sirredbeard mentioned: https://github.com/DamionGans/ubuntu-wsl2-systemd-script
That worked for me 😃, but i don’t understand why, can anyone explain please?
not working, always shows
error: access denied (see 'snap help login')when trying to install or loginjust login to your snap account/ ubuntu one account using
snap login youremail@whatever.comcommandThis is something that is being looked at.
Implementing in a non-hacky way that can be supported long-term without a lot of secondary issues takes planning.
There is a workaround to get snaps working.
@mahfuzullah I had this problem. I executed
wsl --shutdownfrom windows cmd and then executed those commands again. Now without any login, everything works perfectly.I tried that on kali and it did not work. It basically kills the bash on the third command and I am back in the Powershell. Is there an official ETA to really fix that?
this works on 22.04 now. i upgraded my 20.04 installation using
do-release-upgrade -d.there’s no real documentation on how to set it up, as out of the box it only works if you use the “Ubuntu 22.04” app from the MS store.
wsl-setuppackage installed (the upgrade did this automatically for me)./etc/wsl.conffile (in your Ubuntu file system, not in Windows):nsloginyourself.I had the same problem in Pengwin under WSL2, but before it exits the shell, I get the following message:
nsenter: cannot open /proc/1189/ns/time: No such file or directoryHowever, running
snap versionshow valid information. Now when I runsudo snap list, I get:error: access denied (see 'snap help login')When I run
sudo snap login <email>, I geterror: access denied (see 'snap help login').Any ideas?
881 days after I opened this issue, WSL finally gets official systemd support. Happy to see this issue wasn’t just forgotten about.
Thanks, WSL team! I feel this issue can now be closed.
is this something that is planned to be supported natively out of the box at some point? or is it going to continue to require external manual intervention? i’d prefer to avoid messing with things that i will need to externally maintain over time.
Systemd support is now available in WSL!
I followed the simple instruction in the above article, and
sudo snap install firefoxworked like charm!My
/etc/wsl.conffile includes just 2 lines:replace exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME with exec sudo nsenter -t $(pidof systemd) -m -p su - $LOGNAME
Did you replace the placeholders with your values? You need to execute the first two commands. Then use top (or htop) to find out the PID of systemd and then use it to replace the $(pidof systemd) in the third command and replace $LOGNAME with your login name.
Your script worked flawlessly, many thanks!
Only thing that worked for me!! thanks!
When I tried to execute this command, nsenter: failed to execute 69: No such file or directory
[process exited with code 127 (0x0000007f)]
see https://discourse.ubuntu.com/t/using-snapd-in-wsl2/12113
can confirm this works!
For Anyone stuck on
https://docs.microsoft.com/en-us/windows/wsl/wsl-config#boot-settings states
if anybody knows of a way to make this available on win 10 i wouldn’t mind at all
Yes, I have tried it with the actual PID replacing the $(pidof systemd) and my username (rob) in place of the $LOGNAME. It had the same result. I also shutdown WSL 2 with
wsl --shutdownand then tried again; I got the same result. I would love any further help with this. Thanks!Windows 11 only. Windows 10 later?
https://twitter.com/benhillis/status/1572705529885257729
looks like WSL now officially supports systemd: https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/
For people trying to upgrade from Ubuntu 20.10 to Ubuntu21.04 (on WSL2) but failed due to snapd problem
Just to share my workarounds.
In short …
try this
NOTICE : the last line was changed from the original ones.
backgrouds
I bumped into this snapd problem when I upgradeing from
20.04to20.10. The release-upgrade process failed since snapd was not working. I fixed it with the workaround below, as everyone else might did.This has been working fine but I faced the same problem when I was upgrading from
20.10to21.04. based on this post , I removed some namespace option from the last line of the code, and it worked.I would appreciate any suggestion or option. Thanks in advance.
Confirming this works on Windows 10 😃
Note that Ubuntu 22.04 still requires the whole
/etc/wsl.confthing to enable systemd. For a trully out-of-the-box, no-steps-required experience use Ubuntu-Preview. It also fixes a couple services that fail on WSL.I have
systemd=truein/etc/wsl.conf, and I had snap working briefly. Now I get:Crash terminal immediately after: exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
😦 … !
Also getting access denied when I run
snap login, after running the workaround script and even using a custom kernel.Important: Do not forget to exit wsl via
wsl --shutdownafter editing/etc/wsl.confJust exiting wsl viaexitand entering viawslis not enoughyeah you’ll have to disable the workaround - how you do that really depends on what workaround you used. you can try launching with
wsl -e /bin/shorwsl -e /bin/bash --noprofile norcwhich might get you into a shell where you can remove the workaround.I managed to:
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfigandsudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.targetto get systemd workingexec sudo nsenter -m -u -i -n -p -C -r -w -t $(pidof -s systemd) -a su - $LOGNAMEto upgrade from 20.04 to 21.04 (had to change from ‘lts’ to ‘normal’, it’ll give a warning telling you where to change)exec sudo nsenter -m -u -i -n -p -C -r -w -t $(pidof -s systemd) -m -p su - $LOGNAMEand then upgrade again from 21.04 to 21.10Be sure to backup your VM file though, last time I tried this I had to re-install my entire distro. (We’re supposed to update it manually like that, it’s on the Store’s page) Unfortunately we still need that command in order to use
snap, even though I read somewhere that supposedly it should be supported on one of the newer Ubuntu versions.Thanks, I almost lost my mind.
@sunliusi and @ride4sun and others . . .
I had to include
-s[ingle shot - this instructs the program to only return one pid]switch in the following commandto keep it from terminating my wsl2 ubuntu 20.04 bash terminal session. On that setup
pidof systemdreturns three pids.Any insights on what aspect of my standard issue wsl2 ubuntu 20.04 distribution install might be different that would cause me to have to include that switch when it appears others in this thread did not have to do that?
On my wsl2 kali-linux install
pidof systemdonly returns one hit so that command terminates my wsl2 kali-linux 2021.1 bash terminal session with and without the -s switch included.Thanks! Works for me!
Yes, there are some details displayed by
wsl --helpand on Microsoft docs as well:Update your WSL version to the latest version. Options include:
--web-download: Download the latest update from the GitHub rather than the Microsoft Store.Essentially your wsl package is updated to the latest version.
GitHub really should have a pin feature for issues. Successfully logged in to Snapd with that updated command. Hopefully I won’t have to run this one anymore. Ty for perfecting my WSL setup even more @chari8
You didn’t install
snapdfind a way to retain the environment.
first, install the dependency
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfigthen add following commands into the file
/etc/bash.bashrc(/etc/zsh/zshrcforzsh):FYI: if you can’t enter the wsl2 after changing the setting file, you can run the command
wsl shto bypass above commands.I use this under Ubuntu 20.04.1 LTS. Maybe it doesn’t work under Pengwin. Maybe you make a mistake. I’ll show you my approach. Please reboot your pc to get a clean start point. I use the new terminal in windows.
The first command shows some output, no errors, ends with ‘done’. The second and third command show no output. snap version and snap list work fine. No need to use snap login.
Ensure you use the right PID. After the second command use htop. Use F10 to filter the output. Type systemd. There are about eleven entries. Type a space (so you are filtering for 'systemd ', not for ‘systemd’). Now there are only two entries. Use the pid for /lib/systemd/systemd.
If you done it all right I can’t help you, it seems to be a problem with Pengwin, sorry.
I went through all the steps outlined on this article Systemd support is now available in WSL! and it did not work. However I was doing this from a VSCode terminal running WSL. I opened a “normal” wsl window and it worked like a charm (Windows 10).
Exited wsl and ran
wsl --updatein Powershell. Docker installed with snap after that with no issues.March 2023 - Still works like a charm! Thanks!
For what it’s worth, I’m using Windows 10, build 19044.2364, and I was able to install Firefox via Snap after doing
wsl --update.@Archsx
Did you read this?
Looks like this is being discussed here: https://github.com/ubuntu/WSL/issues/299
On Windows 10 21H1, build 19043.2130, following the instructions I have edited:
Restarted WSL:
But I still get the error of the original post:
I tried on Windows 11 and it worked.
I get this kind of error, /usr/bin/firefox: 12: xdg-settings: not found Error: cannot open display: :0
Does Firefox work on 22.04 with https://github.com/microsoft/WSL/issues/5126#issuecomment-1111957720 ? After
snap install firefox:That
cannot open displaything reminds me the old days when we had no GUI support 🤔Windows Terminal did the last automatically for me after updating. Inside VSCode, I needed to add this to
settings.json:Unless someone finds a more straightfoward way to do it.
Thank you @hyoretsu . That would have been obvious if I had investigated the Heroku URL; I realize now that Heroku was throwing the “NoSuchKey” error, not
snap. Great work @edmondium ! The proposed solution worked.After running the above commands with the modification proposed by @edmondium,
snap versionworked, but trying to actually usesnap, I then got the error below: (Windows 11 Pro + WSL2 + Ubuntu focal)My current workaround
this one solves the broken snap packages issue https://github.com/DamionGans/ubuntu-wsl2-systemd-script/pull/49/files
this one solves the wslg issue https://gist.github.com/mfkenson/5bd85aa22c4c63fbed6845d545e61361
https://github.com/microsoft/wslg/issues/479
https://github.com/arkane-systems/genie/issues/175#issuecomment-922526126
Try this command (Mine’s aliased under x11 command for quick access)
Close command line open PowerShell and enter the following command then re-open the ubuntu command line
wsl.exe --terminate ubuntuStarted getting
nsenter: cannot open /proc/9286/ns/time: No such file or directorywhen runningssnapafter upgrading Ubuntu to v21.04. Trying to start Docker throwsTransport endpoint is not connectedEDIT: Apparently it is stuck in a state of endless boot
Hi! Very cool script, and it managed to make snapd work on my machine(Windows11 build 22000.100, WSL2, Ubuntu 20.04 LTS, Kernel Version 5.10.43.3)! But it seemingly breaks wslg supports meanwhile, all GUI programs reported that they cannot connect to DISPLAY :0. I have tried reinstalling my WSL distro, and wslg works again. Running the script, and wslg breaks again. Removing the script and restarting wsl instance(i.e.wsl --shutdown, logout-and-login doesn’t help) recovers wslg supports but, of course, the systemd is gone. I have searched around google and found that nobody else encounters the same problem. Isn’t this script meant to work with wslg? Or this is an unknown mysterious bug of the Dev-Channel build? Is there any workaround?EDIT: This is fixed by running
sudo mount --bind /mnt/wslg/.X11-unix /tmp/.X11-unixAfter running this solution, I was able to get snap working BUT, VS Code Server stopped working. When I type “code” on the command prompt, I get a message asking to install “code” from snap.
How can I do so that I don’t have to execute these commands every time I reboot?
broke my distro. had to delete and reinstal.