2

Summary

I can no longer open GUI applications from WSL. The only thing that changed recently was a new Windows update.

System Info

I am on Windows 11 Home version 23H2, build 22631.3737 Windows Feature Experience Pack 1000.22700.1009.0 using WSL 2

I have the following in my ~/.bashrc file:

# allow X11 to work
export DISPLAY="$(grep nameserver /etc/resolv.conf | sed 's/nameserver //'):0.0"
export LIBGL_ALWAYS_INDIRECT=1

And my DISPLAY variable looks like this:

$ echo $DISPLAY
10.255.255.254:0.0

I run XLaunch with these settings:

<?xml version="1.0" encoding="UTF-8"?>
<XLaunch
  WindowMode="MultiWindow"
  ClientMode="NoClient"
  LocalClient="False"
  Display="-1"
  LocalProgram="xcalc"
  RemoteProgram="xterm"
  RemotePassword=""
  PrivateKey=""
  RemoteHost=""
  RemoteUser=""
  XDMCPHost=""
  XDMCPBroadcast="False"
  XDMCPIndirect="False"
  Clipboard="True"
  ClipboardPrimary="True"
  ExtraParams=""
  Wgl="True"
  DisableAC="True"
  XDMCPTerminate="False"
/>

Description

This setup has been working for years. I updated my PC over the weekend and turned it on this morning to find the message "Error: Can't open display: 10.255.255.254:0.0" every time I try to launch a GUI program.

Any ideas on what went wrong? I'd like to be able to run GUI applications from WSL again.

4
  • Alternatively, you might considering using WSLg instead of running an X server in Windows.
    – josh3736
    Commented Jun 25 at 1:52
  • @josh3736 I looked at the readme and these instructions. I am able to launch one Linux program from the Windows start menu. But I still got the "Can't open display" error when launching from WSL. I tried shutting down the X server and I still got the error.
    – nullromo
    Commented Jun 25 at 19:19
  • Is the export DISPLAY=… in your bashrc is overriding whatever WSLg sets?
    – josh3736
    Commented Jun 26 at 1:00
  • Ah, yes that's what happened. If you leave DISPLAY as just :0 then WSLg takes over. Thanks! I will edit the answer accordingly.
    – nullromo
    Commented 2 days ago

1 Answer 1

2

Option 1: Change $DISPLAY

Use

export DISPLAY=$(ip route list default | awk '{print $3}'):0

Now the $DISPLAY variable looks like this:

$ echo $DISPLAY
172.30.176.1:0

Option 2: Use WSLg

WSL now has a built-in feature called WSLg that handles GUI programs. To use it, simply remove any export DISPLAY=.... You don't even need to run an X server.

The $DISPLAY variable should look like this:

$ echo $DISPLAY
:0
1
  • Both options work, but be cautioned that I had performance issues with the WSLg version. gitk was lagging a lot and sometimes it would not take any mouse input. It sometimes takes two Alt-TAB's to move away from the window. Almost all operations took at least 3 times as long in the WSLg version.
    – nullromo
    Commented 2 days ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .