46

I am trying to install heroku cli using

sudo snap install heroku --classic

The command line says

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

I tried systemctl status snapd.service this is the result :

snapd.service
   Loaded: masked (/dev/null; bad)  
   Active: inactive (dead)

I tried systemctl restart snapd.service it says:

Failed to restart snapd.service: Unit snapd.service is masked.

Any help on above problem in appreciated. Thanks.

Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • 3
  • 5
    For anyone seeing this issue with Windows Subsystem for Linux (WSL) see - https://github.com/microsoft/WSL/issues/5126

    Run this before attempting a snap install - it should work:

    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

    – Chris Halcrow Mar 24 '22 at 04:10
  • 1
    Add these lines to the /etc/wsl.conf (note you will need to run your editor with sudo [boot] systemd=true after that, you should run wsl.exe --shutdown – Felipe Pereira Mar 16 '23 at 20:11

2 Answers2

40

Unmask the snapd.service:

sudo systemctl unmask snapd.service

Enable it:

sudo systemctl enable snapd.service

Start it:

sudo systemctl start snapd.service

Then try installing your desired app.

rluks
  • 171
Ravexina
  • 55,668
  • 25
  • 164
  • 183
  • 11
    I am running WSL based on Ubuntu Linux, And running these instructions gives error after last command: System has not been booted with systemd as init system (PID 1). Can't operate. – Andy Aug 17 '21 at 14:55
  • 13
    If you are using WSL then this answer is not applicable to your situation. Basically because there is no systemd on WSL in the first place. However this might be helpful to you. – Ravexina Aug 17 '21 at 16:31
  • 19
    I am inside a docker image of ubuntu. Running systemctl start snapd.service returns System has not been booted with systemd as init system (PID 1). Can't operate. – Jortega Sep 13 '21 at 23:00
  • @Jortega Did you ever find a solution? I'm thinking based on other discussions that trying to run snapd without systemd isn't worth the headache. – Brian Z Feb 04 '23 at 20:26
  • @Ravexina systemd is on WSL, but may be disabled. I had this issue with WSL on Ubuntu 24.04 pre-release, where systemd was disabled by default, and fixed it by adding [boot] systemd=true to /etc/wsl.conf and restarting WSL :) – hanshenrik Jan 28 '24 at 08:16
  • @Andy I think my answer would solve your problem. – hanshenrik Jan 28 '24 at 08:26
  • @Jortega I think my answer would solve your problem. – hanshenrik Jan 28 '24 at 08:26
  • @BrianZ I think my answer would solve your problem. – hanshenrik Jan 28 '24 at 08:27
0

for a WSL-specific answer, I had this problem on WSL Ubuntu 24.04 pre-release where systemd was disabled, giving me errors like

$ snap install chromium
error: cannot communicate with server: Post "http://localhost/v2/snaps/chromium": dial unix /run/snapd.socket: connect: no such file or directory
$ sudo systemctl start snapd.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

and I fixed it by adding

[boot]
systemd=true

to /etc/wsl.conf , then restarting WSL :) (starting PowerShell as administrator and running wsl --shutdown), now Snap works great.

In comments to Ravexina's answer, I think this would solve the problem of Andy, Jortega, and Brian Z.. but i have no way to ping them.

hanshenrik
  • 324
  • 2
  • 15
  • 1
    Followed all these steps on WSL 2 Ubuntu, no dice. Still having issues with Snap after restarting with systemd enabled via that config. – ajmeese7 Mar 20 '24 at 23:55
  • @ajmeese7 can you pastebin a log? ( for example http://paste.debian.net ) – hanshenrik Mar 21 '24 at 09:46