所以,我尝试安装 VS Code:
sudo snap install code --classic
但我收到以下错误:
error: cannot communicate with server: Post http://localhost/v2/snaps/code: dial unix /run/snapd.socket: connect: no such file or directory
我不知道该怎么办,我什至删除并重新安装了 snap,但错误仍然出现......
我做了:
sudo apt autoremove --purge snapd
进而:
sudo apt update && sudo apt upgrade
sudo apt install snapd
这不起作用!
然后我尝试:
sudo service snapd start
输出:
snapd: unrecognized service
如果我做:
snapd services
输出:
snap 2.54.3+20.04.1ubuntu0.2
snapd unavailable
series -
使用命令:
systemctl status snapd.service
我得到以下信息,我的系统使用 sysvinit:
System has not been booted with systemd as init system (PID 1).
Can't operate.
Failed to connect to bus: Host is down
发生这种情况的原因是什么?我正在使用 wsl2
答案1
如果您使用的是 Windows WSL,请运行以下命令:
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
sudo bash ubuntu-wsl2-systemd-script.sh
# Enter your password and wait until the script has finished
cmd.exe /C setx WSLENV BASH_ENV/u
cmd.exe /C setx BASH_ENV /etc/bash.bashrc
在此处检查 WSL 中的 systemd 和 snap 的问题: