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

1.软件环境⚙️2.问题描述3.解决方法3.1.设置在 WSL 发行版中启用 systemd3.2.检查systemctl的运行状态3.3.重新使用snap安装pycham

4.结果预览樂

1.软件环境⚙️

Windows10 教育版64位 WSL 2 Ubuntu 20.04 LTS

2.问题描述

在WSL中使用snap命令:

sudo snap install pycharm-professional --classic

安装Pycharm专业版时出现:

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

那这个时候又该怎么办呢?

3.解决方法

查了一下有人说是snapd的服务没有启动,因此启动它:

sudo systemctl start snapd

但是却发生了报错:

System has not been booted with systemd as init system (PID 1). Can't operate.

如果你是原生的Ubuntu系统,那么上述步骤应该可以工作,但因为WSL毕竟和原生的Ubuntu系统有区别,WSL开机并不会启动Systemd的支持,而snap和systemctl依赖于Systemd:

snap: 一个方便的二进制文件,允许在 Ubuntu 中安装和管理软件。 如:snap install spotify 或 snap install postman microk8s: 让 Kubernetes 在您的系统上快速本地运行 systemctl: 作为 systemd 一部分的工具,与 Linux 机器上的服务交互; 使用 systemctl list-units --type=service 查看可用的服务及其状态

好在WSL 0.67.6 及更高版本已经能够支持Systemd,只是需要我们自己修改相应的配置:

3.1.设置在 WSL 发行版中启用 systemd

[boot]

systemd=true

将上述代码添加到/etc/wsl.conf,然后保存并关闭即可! PS:啥编辑器都行(vim、gedit、nano都可以),例如: sudo nano /etc/wsl.conf

3.2.检查systemctl的运行状态

完成上述步骤后,关闭WSL 并从 PowerShell 运行 wsl.exe --shutdown 以重新启动 WSL 实例。 启动后,应该已经运行了 systemd,可以使用命令 systemctl list-unit-files --type=service 检查一下,这个时候应该显示systemctl 的具体服务状态:

3.3.重新使用snap安装pycham

4.结果预览樂

可以看到,已经安装成功:

​ 渣男!都看到这里了,还不赶紧点赞,评论,收藏走一波?

相关文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。