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.

3
  • 3
    Related: systemctl, how to unmask
    – Ravexina
    Jul 11, 2020 at 7:43
  • 5
    For anyone seeing this issue with Windows Subsystem for Linux (WSL) see - 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 Mar 24, 2022 at 4: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 Mar 16, 2023 at 20:11

2 Answers 2

41

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.

8
  • 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, 2021 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, 2021 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, 2021 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 4, 2023 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 at 8:16
1

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.

3
  • 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 at 23:55
  • @ajmeese7 can you pastebin a log? ( for example paste.debian.net )
    – hanshenrik
    Mar 21 at 9:46
  • Excellent. This worked on WSL.
    – pratnala
    May 26 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .