Sometimes, we do need to use Windows, and sometimes, while on Windows, we need to use a Linux-only tool.
When this tool is CLI-based, WSL comes in as a handy solution that allows us to have a local Linux CL environment.
But, sometimes, we may want, or need, to run a Linux-based GUI software.
While not natively doable on WSL, we can install a tool that will allow us to run GUI softwares from WSL on our Windows computer.
Linux handles the GUI under the form of, like most of the system, a daemon and server.
The softwares run attached to this server, and this server is made to provide a drawing zone on which they can be displayed.
What we need is an X server on Windows, since it is the OS currently managing our screens.
This can be done using XLaunch, provided by Xming, a Windows implementation of the Xorg system.
The software can be downloaded on the official website.
When time comes to choose what you want to install as components, you can choose to not install PuTTY at all, you shouldn't encounter any issue by doing so.
Once installed, we can start it, to configure its few tweaks.
First, we have the choice of how the X server will integrate itself in Windows.
Since we'd like to avoid the "emulated linux" style, and instead have every software right in Windows, we'll pick the "Multiple windows" option.
We'll set the display number to 0
, and we'll keep that on the side for later.
You may use any display number you want, you only need to keep it known and positive.
Since we only want a X server on windows, and nothing else, we can select the "Start no client" option.
We'd like to share the clipboard, as to be able to copy/paste between Windows and Linux without any issue, and for performance reasons, we'll ask to use native OpenGL implementation.
We don't care about the other settings, and we don't need to pass additional arguments, so we also can leave that empty.
That's it for the configuration! I'd recommend towards saving it in someplace you can easily reach, so you'll be able to double-click the configuration file to automatically launch the pre-configured Xlaunch session.
Now, we finish the configuration, and XLaunch will start!
Windows is now configured to open GUI softwares from WSL.
To test that, we can try to start a GUI software from WSL, like GitK
(which has tk
as dependency, if you get a wish not found
-kind of error).
Instead of only running gitk
, though, we need to inform WSL that a display
server exists.
That is done with the DISPLAY
environment variable.
Remember the display number we kept on the side (which was 0
)?
That's what we need to provide.
The syntax for the DISPLAY
environment variable is :<DISPLAY NUMBER>
,
so we'll need DISPLAY=:0
.
Of course, if you chose another number, use that other number.
$ DISPLAY=:0 gitk
If the software starts, and a gitk window is shown, you've just started your first GUI software from WSL!
If not, you may have skipped a step, so make sure you've done everything correctly.
Now, the last step is to configure your user session to avoid having to pass this annoying environment variable on every GUI software start.
The steps to do so depends on your user shell, I'll show it for Bash and ZSH.
# Bash
$ echo 'export DISPLAY=:0' >> .bashrc
$ source .bashrc # to setup the environment variable right away
# zsh
$ echo 'export DISPLAY=:0' >> .zshrc
$ source .zshrc # to setup the environment variable right away
And that's it! You now can run GUI softwares from Linux on Windows, without the need for emulation, or an entire desktop environment!