How to fix Snap error during Flutter installation in WSL-2 Ubuntu.

hfzwhd
3 min readSep 28, 2021

--

So I tried installing flutter on my wsl-2 using the guide provided on their website but encountered some errors that I managed to overcome, so I think it’s better to share it here to help anyone who might need it.

My windows terminal with groovy gorilla as background.

According to the flutter website, there are two ways to install flutter for linux. The first is by using snap, which will be shared in this article, and the second is by installing it manually, by following a few provided steps. I chose the first option just because it is a one line command. Alternate to that, you can also choose to install flutter with just a point ’n’ click using the snap store.

So the only command needed is;

sudo snap install flutter — classic

That’s it, and everything should go smoothly and you can get on with life as usual.

But unfortunately that’s not what happened to me. I got an error output like the following;

error: cannot communicate with server: Post http://localhost/v2/snaps/flutter: dial unix /run/snapd.socket: connect: no such file or directory

A job that was supposed to be easy but turned out to be the other way around. So, without thinking twice, I concluded that maybe it was caused by an application(snap) that is not properly installed.

So I ran the following command to remove the snap and reinstall it, kinda turn on-and-off approach. LOL.

sudo apt autoremove — purge snapd

sudo apt install snapd

But then, I still get exactly the same error.

sysytemctl status snapd.service

Then I run the above command just to see if the snap is running as it should but the command doesn’t return any output — just hangs on forever. So from there I assumed all this happened because snap service was not run, so I shot the below command to start the service.

sudo systemctl enable snapd.service

Still does not return any output and hangs on forever.

So I start googling and I finally found an article that is published during 2019, which is specifically for users who want to use snap in ubuntu wsl-2.

To cut a long story short the problem is because Microsoft is using a custom init that sets up what is effectively a container for each installed wsl-2 distribution. This init system is minimal and handles integration with wsl more than the tasks of a traditional distribution init system.

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

After that, you can install the flutter successfully without any problems.

You may refer to the article if you need more information on each executed command.

--

--