Do I launch the app XLaunch for every login to use GUI in Ubuntu WSL in windows 10 pro?
Solution 1:
Let have some background first. To configure general X11 connection, we have to set the DISPLAY
variable in WSL with this command export DISPLAY=:0
. Also don't forget to use this export LIBGL_ALWAYS_INDIRECT=1
command which enables direct rendering. If these were done then go to the next step: configuring VcxSrv.
VcxSrv has many command line options (XWin man page). You can get the option details with vcxsrv.exe --help
command. For WSL, mainly three options are required (can be changed).
-multiwindow
Run the server in multiwindow mode.-clipboard
Enable [disable] the clipboard integration. Default is enabled.-wgl
Enable the GLX extension to use the native Windows WGL interface for hardware-accelerated OpenGL.
The command will be: vcxsrv.exe :0 -multiwindow -clipboard -wgl
.
Now the final step is to launch it before WSL launches. There may be multiple ways to do this. Here I mention two of them.
- Create a shortcut with that previous command. You should mention the full path in that command. e.g.
E:\VcXSrv\vcxsrv.exe :0 -multiwindow -clipboard -wgl
. Here is a screenshot.
Then put that shortcut in %AppData%\Microsoft\Windows\Start Menu\Programs\Startup
folder to automatically start VcxSrv when PC boots up.
- Another way is to add the full command in registry with this command as administrator:
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /V VcxSrv /D "E:\VcXSrv\vcxsrv.exe :0 -multiwindow -clipboard -wgl"
Follow any one of the above two methods, not both. VcxSrv.exe
will launch when you restart your PC.
Solution 2:
-
Open
%AppData%\Microsoft\Windows\Start Menu\Programs\Startup
in File Explorer -
Create there a new file named
config.xlaunch
with the following content:<?xml version="1.0" encoding="UTF-8"?> <XLaunch WindowMode="MultiWindow" ClientMode="NoClient" LocalClient="False" Display="0" LocalProgram="xcalc" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="False" ExtraParams="" Wgl="True" DisableAC="True" XDMCPTerminate="False"/>
Solution 3:
An easy solution I've found to work:
-
Run XLaunch, choose your desired settings, and click "Save configuration" just before Finish.
-
Save the config file in your Startup folder which you can find by hitting
Windows key + r
and runningshell:startup
.
This will launch an Xserver with the saved configuration when Windows starts.
For WSL2, see this question to have your .bashrc
set DISPLAY
when starting Ubuntu/WSL, which also links to this subsection to let the WSL2 subnet through Windows firewall.