Graphics in WSL
Currently, Window’s subsystem for Linux (WSL) supports only command-line applications and does not natively support graphics. Nevertheless, it is possible to run a X server like VcXsrv, on Windows and run X applications as clients under WSL.
Let’s get started!
Step 1: Install VcXsrv as a X server which works good on WSL (you can even go for Xming or Cygwin/X). Follow the link and click on Download.
Step 2: Assuming you have installed WSL, open the command line of windows and type bash or you can directly open bash on Linux distro you have installed. Write a command sudo apt install xfce4
press enter, it’ll ask for a password. Give the password and hit enter.
Step 3: Once installation is done enter cd
and then open the .bashrc using command nano .bashrc
, scroll till the end of the file and add this line at the bottom export DISPLAY=:0.0
(Right click to paste). Save the changes (ctrl + x, write Y and hit enter)
Step 4: Once the VcXsrv is downloaded, install it with default settings and start the XLaunch program. This window will appear.
Select One large window and click next
Select Start no client, click next
Make sure all four checkboxes are marked then click next
Press Finish and come back to your bash
Step 5: Write a command xfce4-session
to launch XLaunch ;)
Yay it’s done!!
Just open the terminal and run your graphics code.
To log out from the server, click on Applications -> Log Out -> Log Out.
Hope you find it useful. Have a nice day! :)