Skip to content

Instantly share code, notes, and snippets.

@ajitid
Last active April 9, 2024 07:03
Show Gist options
  • Save ajitid/0121c0bd56287a43cf3023d996527606 to your computer and use it in GitHub Desktop.
Save ajitid/0121c0bd56287a43cf3023d996527606 to your computer and use it in GitHub Desktop.
Run GUI applications in WSL1
# C:/Users/zlksnk/.wslconfig
# [wsl2]
# kernel=<path> # An absolute Windows path to a custom Linux kernel.
# memory=<size> # How much memory to assign to the WSL2 VM.
# processors=<number> # How many processors to assign to the WSL2 VM.
# swap=<size> # How much swap space to add to the WSL2 VM. 0 for no swap file.
# swapFile=<path> # An absolute Windows path to the swap vhd.
# localhostForwarding=<bool> # Boolean specifying if ports bound to wildcard or localhost in the WSL2 VM should be connectable from the host via localhost:port (default true).
# <path> entries must be absolute Windows paths with escaped backslashes, for example C:\\Users\\Ben\\kernel
# <size> entries must be size followed by unit, for example 8GB or 512MB
[wsl2]
memory=4.5GB

This is mostly taken from Shogan's blog which also covers PulseAudio.

Prerequisites

  • You'll need admin privileges in Windows to install a software.
  • Around 1.5 GB of data will be downloaded so be mindful if you are on a limited data connection.

Steps

  • Firstly, update your packages using sudo apt update and sudo apt dist-upgrade.
  • On Ubuntu shell install Xfce using sudo apt install xfce4 xfce4-goodies. On Kali linux it can be installed using sudo apt install kali-desktop-xfce.
  • Xfce would be paused in mid-install. You’ll be prompted about which display manager to use. This is up to you, I chose lightdm.
  • While Xfce is installing, download and install VcXsrv Windows X Server either from Sourceforge or from here. I had to use the latter becaue download speed from the former was slow for me. If you are using the latter the installer is named vcxsrv-64.1.20.8.1.installer.exe, rest of the files are unnecessary for us.
  • Once VcXsrv is installed go to its installed location (which most probably is C:\Program Files\VcXsrv), right-click xlaunch.exe and go to Compatibility, click on Change high DPI settings and choose Override high DPI scaling behavior. Ensure Application is in the dropdown.
  • Open Windows Defender Firewall with Advanced Security and add an inbound rule for VcXsrv with the following properties:
    • Type: Program
    • Program path: %ProgramFiles%\VcXsrv\vcxsrv.exe
    • Allow the connection
    • Profile: Domain, Private
    • Name it whatever you like
  • Once everything is installed, open a bash shell (bash, fish, doesn't matter) and type export DISPLAY=:0 and export LIBGL_ALWAYS_INDIRECT=1. Now open VcXsrv (named as XLaunch) on Windows, choose Display number as 0, click Next, keep Start no client as selected, click Next, make sure Native opengl is ticked, click Next, and then on Finish. Its icon will now appear on sytem tray.
  • We have specified options with same values on both OS in previous step. This is needed.
  • Now you can open aopen any program to verify it. For example, I can find correct location of Sublime Merge using which -a smerge and launch it.
  • Onivim 2, on the other hand opens but shows black screen. To fix that, open system tray on Windows, right click on VcXsrv icon and close it. Open a bash shell and enter export LIBGL_ALWAYS_INDIRECT=0 and Launch VcXsrv again but this time on third screen untick Native opengl. Try running the app again.

Notes for WSL2

@ajitid
Copy link
Author

ajitid commented Apr 28, 2021

Also follow this blog to get more memory back and run WSL smoothly. I've given 4.5GB memory in my case. (.wslconfig)

There are more posts on the same though I haven't look through them:

@ajitid
Copy link
Author

ajitid commented Apr 28, 2021

GUI applications now can be run w/o any setup. It also leverages graphics of Windows which wasn't possible until this arrived. But I'll still recommend that memory config.

@ajitid
Copy link
Author

ajitid commented May 30, 2021

Remove windows apps and paths from Linux:

Additional fish config for the same:

# remove Windows from PATH
# see https://github.com/microsoft/WSL/issues/1493#issuecomment-797575704
set PATH (/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')

If chrome-launcher (Node.js/NPM package) isn't able to launch Chrome in WSL2, you need add Windows AppData path like:

export PATH="$PATH:/mnt/c/Users/zlksnk/AppData/"

@ajitid
Copy link
Author

ajitid commented May 30, 2021

@tgastudillo
Copy link

it worked perfect, thanks. I was having trouble running openfoam paraview on ubuntu wsl and this helped me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment