Skip to content

Instantly share code, notes, and snippets.

@djfdyuruiry
Last active March 7, 2024 03:41
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save djfdyuruiry/3150b9e5f3dadba89ea323df49ea7ab1 to your computer and use it in GitHub Desktop.
Save djfdyuruiry/3150b9e5f3dadba89ea323df49ea7ab1 to your computer and use it in GitHub Desktop.
WSL 2 - XServer Setup

WSL 2 XServer Setup

This guide will setup WSL 2 to be able to connect to an XServer installed on your host Windows machine. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2. The XServer software used was VcXsrv; remember to disable authentication for this to work correctly.

  • Open a WSL terminal

  • Fix an issue with dbus:

    sudo sh -c "dbus-uuidgen > /etc/machine-id"
  • Update ~/.zshrc:

    # X Server
    export $(dbus-launch) # not needed if you have systemd enabled
    export LIBGL_ALWAYS_INDIRECT=1
    
    export WSL_HOST=$(cat "/etc/resolv.conf" | grep nameserver | awk '{print $2}' )
    export DISPLAY="${WSL_HOST}:0"
  • Close and reopen the terminal and prove it works:

    sudo apt-get install -y x11-apps
    xeyes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment