When moving from WSL1 to WSL2 many things change; apparently this applies to X11 forwarding as well.
What steps do I need to make in order to use X11 forwarding with WSL
The solution from https://github.com/microsoft/WSL/issues/4793#issuecomment-588321333 uses VcXsrv as the X-server, and it is where I'm getting this answer (slightly edited for readability). Note that the original is being updated by its author, so don't forget to re-check.
To make it work:
- On Windows, with the following, change
E:\VcXsrvto where your installation is, and save it as xxx.bat in your Windows startup folder, e.g.,C:\Users\Me\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup, and you can make it run when boot if you like:@ECHO OFF REM Start WSL once to create WSL network interface wsl exit REM Find IP for WSL network interface SET WSL_IF_IP= CALL :GetIp "vEthernet (WSL)" WSL_IF_IP ECHO WSL_IF_IP=%WSL_IF_IP% setx "WSL_IF_IP" "%WSL_IF_IP%" setx "WSLENV" "WSL_IF_IP/u" REM Change E:\VcXsrv to your VcXsrv installation folder START /D "E:\VcXsrv" /B vcxsrv.exe -multiwindow -clipboard -nowgl -ac -displayfd 720 GOTO :EOF :GetIp ( aInterface , aIp ) ( SETLOCAL EnableExtensions EnableDelayedExpansion FOR /f "tokens=3 delims=: " %%i IN ('netsh interface ip show address "%~1" ^| findstr IP') DO ( SET RET=%%i ) ) ( ENDLOCAL SET "%~2=%RET%" EXIT /B )
- In WSL, edit ~/.bashrc file to add following lines:
export DISPLAY=$WSL_IF_IP:0 unset LIBGL_ALWAYS_INDIRECTThat's all to make WSL2 work automatically. The idea is to get the private LAN IP of WSL interface on Windows, and use Environment variable to pass it to WSL. WSL then updates this LAN IP to DISPLAY for X-Server connection.
The clipboard works well, too, with this setup. I tested this with a WSL2 install of Ubuntu 20.04 LTS.