注:安装了VcXsrv,就不用在安装Xming了
1. VcXsrv的安装
前两步,按照默认选项安装
第三步,一定要勾选Disable access control选项,否则无法正常显示
点击“完成”结束安装,此时桌面有一个Xlaunch图标,菜单栏右下角出现Xlaunch角标,这表示安装成功。
2. wsl2终端安装xfce4
sudo apt install -y xfce4
3. 配置DISPLAY环境变量
首先要查看linux子系统是wsl1还是wsl2。如果是wsl1,直接在.bashrc文件里写入export DISPLAY=:0.0即可。如果是wsl2,则需要查看Windows系统和wsl2之间通信的网卡地址,根据网卡地址配置DISPLAY环境变量。
1.查看Windows系统和wsl2通信间的网卡地址$ sudo vim /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 = falsenameserver 172.21.208.12.nameserver后即是网卡地址3.添加DISPLAY环境变量$ echo -e “\n##DISPLAY Configuration” >> ~/.bashrc #配置声明$ echo “export DISPLAY=172.21.208.1:0.0” >> ~/.bashrc #添加配置,注意在网卡地址后添加:0.0$ source ~/.bashrc4.启动xfce4$ startxfce4
若wsl2字系统按照DISPLAY=0:0方式配置环境变量,则启动xfce4时会出现如下错误
$ startxfce4/usr/zjdwd/startxfce4: X server already running on display :0.0xrdb: Connection refusedxrdb: Can’t open display ‘:0.0’Unable to init server: Could not connect: Connection refusedxfce4-session: Cannot open display: .Type ‘xfce4-session –help’ for usage.