一、下载并安装Linux内核更新包
参考微软官方文档
二、将分发版版本设置为 WSL 1 或 WSL 2
可打开 PowerShell 命令行并输入以下命令(仅在 Windows 内部版本 18362 或更高版本中可用),查看已安装的Linux发行版的WSL版本:
wsl --list --verbose //可简写为:wsl -l -v
设置某发行版的WSL版本:
wsl --set-version <distribution name> <versionNumber>
把distribution name替换为上面wsl -l -v
显示的分发版的实际名称,并将versionNumber替换为数字“1”或“2”即代表需要设置为WSL1还是WSL2。
将安装的任何新分发版的版本默认设置为 WSL2:
wsl --set-default-version 2
三、配置WSL2为静态IP
由于WSL2静态IP比较困难,所以采用变通方法:
在windows主机安装wsl2host服务,wsl2host通过注册一个服务自动修改windows主机host域名如:ubuntu2004.wsl解析到WSL的动态IP。如果运行wsl2host.exe输入的用户名密码不对,可以到计算机管理>服务>WSL2 Host 手动修改使用的用户名和密码。
tips: 现在windows10 已经可以直接使用localhost访问wsl2了。
四、打开了mobaXterm的X-Server但运行xclock依然提示cannot open display
root@BENHILL-DELL:/mnt/c/Users/benhill# cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 192.168.110.177
Then you'll run:
export DISPLAY=192.168.110.117:0
You may also need to launch vcxsrv with the -ac argument.
This is an area that we are working on improving in an update soon.
https://github.com/microsoft/WSL/issues/4106#issuecomment-501532834