How run GUI apps with Windows Subsystem for Linux
I'm running a Windows 10 computer, and have recently installed Windows Subsystem for Linux. This generally creates a single terminal with no "display" environment. It seems that "TMUX" can be used to get several terminals, but this doesn't let you use any sort of graphical display.
I'd like to open a Linux browser, such as Firefox, through Windows Subsystem for Linux.
I tried the suggestions here, but I just get the error:
no DISPLAY environment variable specified
See Ubuntu wiki Running Graphical Applications.
You need to install on Windows an X-server to be launched from Windows to be used by WSL graphical applications.
You may use any of X410, VcXsrv, MobaXTerm, Cygwin/C, Xming, Cygwin X, vcXsrv.
If graphical applications can't connect to the running X server automatically paste the following commands to the terminal before starting the applications or set them on every login by adding them to ~/.bashrc
:
export DISPLAY=:0 # in WSL 1
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # in WSL 2
export LIBGL_ALWAYS_INDIRECT=1
Another useful article is Running Graphical Programs on Windows Subsystem on Linux.
Adding an answer with more recent information than was available at the time the question was originally asked, primarily because I'm linking to this question/answer for other duplicates (here and on Stack Overflow, where it's general an off-topic question).
At the time of this answer, the Windows 10 version of WSL does not support graphical Linux applications. Normally, the DISPLAY environment variable would point to the X Server on which you wanted to display the application. However, there's no X Server with WSL.
There are (at least) three options:
-
For Windows 10, the typically recommended solution is the one that harrymc offers of installing a third-party X server. I won't repeat the information on how to do so since it's already covered in that answer.
-
My preferred solution on Windows 10 is to install
xrdp
and just access a Linux desktop using Windows Remote Desktop connection. See my steps for doing so in this Ask Ubuntu answer. Note that onlyxfce
is really necessary, although the answer includes more detail on running something more complex like Gnome Desktop. -
For those able to upgrade to Windows 11, the WSLg feature there is built-in and allows Linux GUI apps to run without additional configuration. It will even add a Windows Start Menu shortcut for the Linux app.
-
The following is no longer an option as WSLg support has been removed from Windows 10 Dev builds and (at least at this time) is no longer planned to be released for Windows 10.
Not Recommended: Opt in to the Windows Insider program and install a preview version of Windows 10 or Windows 11. Microsoft has added a new feature to WSL called WSLg for running graphical applications. Given the "in development" status of the Previews, I do not recommend this for day-to-day use at this point.