Skip to content

Instantly share code, notes, and snippets.

@Ge-lx
Created April 11, 2022 10:23
Show Gist options
  • Save Ge-lx/1982306b97b09b5f08d501cd4b48d929 to your computer and use it in GitHub Desktop.
Save Ge-lx/1982306b97b09b5f08d501cd4b48d929 to your computer and use it in GitHub Desktop.

WSL 2 Gui Setup

Based on this guide: https://medium.com/@japheth.yates/the-complete-wsl2-gui-setup-2582828f4577

Make sure you are running WSL2:

  • Enable WSL2 features

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  • Update WSL and set default version for ubuntu (replace with your distro, if wsl --list shows different name)

    wsl --status
    wsl --list
    wsl --update
    wsl --shutdown
    wsl --set-default-version
    wsl --set-version ubuntu 2
    

Install X-Server for Windows

Download VcXsrv

Start it by searching for XLaunch and use options:

  • Multiple windows
  • uncheck [ ] Naive Opengl
  • check [x] Disable auth

Install gui dependencies in ubuntu

  • xorg graphical user interface base system

    sudo apt install xorg

  • xorg dev libraries

    sudo apt install libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev

  • opengl dev libraries

    sudo apt install freeglut3 freeglut3-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev

Configure ubuntu to use X-Server in windows

Add the following lines to the end of ~/.bashrc

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
export LIBGL_ALWAYS_INDIRECT=0
sudo /etc/init.d/dbus start &> /dev/null

Restart WSL by closing all wsl clients, running wsl --shutdown and starting it again.

Test

In WSL console, run xeyes

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