![无法在 ubuntu 中使用 snap 安装任何东西](https://linux22.com/image/204410/%E6%97%A0%E6%B3%95%E5%9C%A8%20ubuntu%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20snap%20%E5%AE%89%E8%A3%85%E4%BB%BB%E4%BD%95%E4%B8%9C%E8%A5%BF.png)
所以,我尝试安装 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 的问题: