Search code examples
linuxubuntusfmlwindows-subsystem-for-linux

Failed to open X11 display - How to execute SFML output on WSL - Load WSL GUI apps


have any of you tried compile and executing SFML c++ project output on wsl? I tried and got

Failed to open X11 display; make sure the DISPLAY environment variable is set correctly
Aborted

Is it possible at all to execute GUI applications through wsl?

(I've installed ubuntu's for wsl)


Solution

  • Linux distributions set up for WSL 1 will not function with Linux GUI applications, which are only supported with WSL 2.

    Due to the official documentation from Microsoft regarding WSL, you might need to check these steps:

    Select Start, type PowerShell, right-click Windows PowerShell, and then select Run as administrator. after that type this command and then press enter:

    wsl --update
    

    You will need to restart WSL for the update to take effect. You can restart WSL by running the shutdown command in PowerShell.

    wsl --shutdown
    

    now, once again open powershell and type in this command:

    wsl --list --verbose
    

    You should see the number 2 for your installed distro under the heading VERSION in the response.

    If everything went as planned until this point, see if your distro can open any windows by installing a GUI app like gedit and trying to open it:

    sudo apt update
    

    now install gedit:

    sudo apt install gedit -y
    

    After the installation has finished, launch gedit by typing gedit in your wsl terminal. A window from wsl inside of Windows should now open, and the issue should now be resolved.

    find more information here: https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps