合 WSL2不能显示图形界面
Tags: 故障处理OSWindows 11WSL2图形界面
现象
1、Unable to init server: Could not connect: Connection refused
(gedit:8890): Gtk-WARNING **: 15:50:26.812: cannot open display:
2、Error: Can't open display: :0
3、Running Firefox as root in a regular user's session is not supported. ($XDG_RUNTIME_DIR is /run/user/0/ which is owned by lhr.)
4、运行cmd.exe也不能跳转到cmd的界面
解决
1、使用非root用户运行图形界面:gedit 或 firefox ,另外确保后台没有gedit进程,“ps -ef | grep gedit
”
2、配置如下的参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | echo "lhrxxt ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers cat >> /etc/profile <<"EOF" export WSL_INTEROP=/run/WSL/8_interop export PATH=$PATH:/usr/lib/wsl/lib:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Users/lhr/AppData/Local/Microsoft/WindowsApps:/mnt/f/platform-tools/ export LANG=C export DISPLAY=:0 export WAYLAND_DISPLAY=wayland-0 export XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir export PULSE_SERVER=/mnt/wslg/PulseServer alias x11="sudo rm -r /tmp/.X11-unix && sudo ln -sf /mnt/wslg/.X11-unix /tmp/.X11-unix" x11 EOF |