3

I am trying to run a program with a GUI on Arch, but it complains that it cannot initialize GTK. The same program works perfectly fine on Ubuntu. Both distributions have DISPLAY set to :0.

Graphical programs were working as expected a few days ago, and I do not remember changing anything which could be relevant.

I have tried launching an X server using XLaunch, which did not appear to have any effect.
Restarting WSL and my computer did not fix the issue, and neither did updating Arch or WSL.
Launching different graphical programs, such as gtkwave or xterm, had the same result. (xterm says Can't open display :0)
Going back in time did not work, as I do not have access to a time machine.
The programs do run as expected in Ubuntu, however I would prefer to use Arch when possible.

1 Answers1

8

Resolved (at least with a workaround) in the comments. And I've now seen what seem to be 3 related questions in the last week about this, so there may be significant issue.

I believe there's a common theme of:

  1. Recent update of WSL2 to 2.1.5 (or 1 previous beta)
  2. Systemd being enabled
  3. Non-Ubuntu (perhaps non-Debian) distribution

If you don't have at least the first two of these, then you are probably looking at a different issue. I'm guessing it's possible for the problem to occur on Ubuntu, but something about the current Systemd loading order on that distro appears to be working to avoid the issue for the most part.

For this particular quetion, the issue was caused when running Systemd inside Arch on WSL2 release 2.1.4, and the issue resolved when disabling Systemd.

That leads up to ...

Option 1: Disable Systemd

If you do not need Systemd in WSL. Run:

sudo -e /etc/wsl.conf

If you have:

[boot]
systemd=true

Then either comment out the system line or set it to false.

Shutdown WSL (or terminate the instance) and restart. This can be done via PowerShell with:

wsl --shutdown

Option 2: Create a link for the X11 socket

If you still need or want to run Systemd, there's another answer here on Super User with a solution that I believe is likely to resolve the issue. The solution from that answer is to:

rmdir /tmp/.X11-unix && ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix

That answer also includes a Systemd unit to automatically handle this on every boot. However, I do recommend occasionally checking to see if there are reports of the issue being fixed, so that you can stop this manually linking in the future. It's possible (but not expected) for this to interfere with other behavior.


For reference, this answer (currently closed, but will probably be Roomba'd at some point) is another case, with a WSL update, OpenSUSE Tumbleweed, and Systemd enabled. Disabling Systemd also resolved that case.

NotTheDr01ds
  • 28,025