4

I am trying to get GUIs working with WSL2, but nothing I tried works.

  1. I turned off the Firewall for home networks (just for testing).
  2. I started Vcxsrv with the following options: Multiple Windows, Display Number: -1, Start no client, Clipboard (with Primary Selection), Native OpenGL and Disable access control.
  3. In Ubuntu, I entered: export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
  4. Then I also entered: export LIBGL_ALWAYS_INDIRECT=1

After having done that, I tried to execute some programs that used to work under WSL1.

In the case of nemo, I get the following error:

Unable to init server: Could not connect: Connection refused
Could not parse arguments: Cannot open display:

When trying to run gedit, I get the following error:

Unable to init server: Could not connect: Connection refused

(gedit:6704): Gtk-WARNING **: 01:07:05.762: cannot open display: 172.19.64.1:0

Entering echo $DISPLAY yields the following output: 172.19.64.1:0

I have also uninstalled Ubuntu, manually deleted the remnants from AppData and made a clean reinstall of Ubuntu. In case that is important: I did not create a UNIX account but use root (both before and after reinstalling Ubuntu so there should be no permission issues on the Ubuntu side).

EDIT 1: I also tried to run both Vcxsrv and Ubuntu as administrator, just to rule out any permission problems on the Windows side of things.

I probably should also add, that I am a Windows Insider (fast ring) and that I have this problem ever since I first tried WSL2 about half a year ago. Forcing me to always downgrade to WSL1 since browsing files without Nemo using just the terminal is a real pain in the ... .

Willi
  • 224
  • 1
  • 2
  • 5
  • Just to confirm, you are indeed running `Windows 10 version 2004` (19041.153)? – Ramhound Mar 26 '20 at 00:20
  • I am a Windows Insider (fast ring). So WSL2 is available for months now (at least for me). But I have failed to get the GUI working for at least half a year now (and therefore always downgraded back to WSL1). So it is not a bug in my current build. My OS Version is 2004 and my OS build is 19587.1000. Windows update is currently downloading build 19592.1001. – Willi Mar 26 '20 at 00:28
  • I also tried pretty much every variation of export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 I could find on the Internet. – Willi Mar 26 '20 at 00:30

6 Answers6

5

To answer my own question in case someone has a similar problem. If I use something like this:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

Running GUI programs simply won't work as they do not seem to find the Xserver (I tried two of them). However, if I manually set the IP address to

export DISPLAY=IPv4_address_of_host:0

it works flawlessly.

I honestly do not know why the first approach seems to work for many if not most people but not for me. But I tried it on three different physical machines and the first approach worked on neither. And neither did any variant of that code I could find on the Internet. I must be a very unlucky man :(.

Anyways, if you have the same problem as me, you should tell your router to always assign the same IP-address to your PC. That way, you can tell your WSL distribution that it should always use the same IP-address which enables you to automate the export DISPLAY=IPv4_address_of_host:0 step.

Willi
  • 224
  • 1
  • 2
  • 5
  • `cat` is unneccessary here.. useless-use-of-cat, since grep has a `[FILE]` arg `export DISPLAY=$(grep -F nameserver /etc/resolv.conf | awk '{print $2}'):0` the `-F` is to use fixed strings (e.g. no regular expressions) so grep runs faster. I like the awk solution better tho `export DISPLAY=$(awk '/nameserver / {print $2;exit}' /etc/resolv.conf):0` – dza Aug 22 '20 at 03:40
  • so when you ```echo $DISPLAY``` now do you get something different than what you mentioned getting in the original post? – Hasse1987 Dec 29 '20 at 17:19
  • I had the same issue and for me it worked when I used my Hosts external IPv4 instead of the one from the WSL subnet. No idea why vcxsrv didn't bind to both interfaces ¯\_(ツ)_/¯ – Cube Jun 07 '22 at 13:06
5

As per wiki WSL - Ubuntu Wiki you can do the following:

 export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # in WSL 2
 export LIBGL_ALWAYS_INDIRECT=1
Bruno Vermeulen
  • 151
  • 1
  • 4
0

I know this thread is a few months old at this point, but in case this helps anyone, the Windows Firewall seems to be preventing WSL to find the X server in my case as well. When I disable my firewall, everything works. I'm looking into what would need to be added to the firewall inbound/outbound rules so the firewall doesn't need to be disabled entirely.

I hope this helps someone!

  • 1
    Adding an inbound rule is the way to go here. Here is how to do it: 1. Identify the IP address of WSL2 instance (example: 123.123.123.123) 2. Add an inbound rule - Rule type: program - Program: path to X-server app - Action: allow connection - Profile: tick all - Add name Once created, click on properties of the rule and add remote IP address scope: - 123.123.0.0 - 123.123.255.255 – Olimjon Aug 02 '21 at 08:16
  • This is the most correct answer, but downvoted. @Willi you can mark this as approved answer. It is necessary to turn off Windows Defender or manually enter the modem IP of windows. – Fahri Güreşçi Apr 02 '22 at 23:12
0

I had troubles with zsh and adding the two following lines to .zprofile solved the issue:

export DISPLAY=$(ip route show default | grep -ioP '\d+\.\d+\.\d+\.\d+'):0
export LIBGL_ALWAYS_INDIRECT=1

I use VcXsrv on my Windows host.

explogx
  • 123
  • 5
0

In my case it wasn't the WSL side, it was xServer side... the message says

Authorization required, but no authorization protocol specified
Unable to init server: Could not connect: Connection refused

On xServer settings, there's a check of accept all incomming connections and that made it work for me.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 08 '22 at 15:34
-2

the above did not work for me but the following worked . the ubuntu destkop installation can be skipped https://medium.com/@japheth.yates/the-complete-wsl2-gui-setup-2582828f4577

Lcat
  • 105
  • 1
    This has good potential to help the question asker, but due to possibility for Link Rot, it is preferable to not rely on the link and always recite the information in the link in your answer, providing the link only as a source. It would be great if you could update your answer as such. – Tyler N Dec 07 '20 at 17:15
  • Link to paywall. – Maxwell175 Feb 15 '22 at 21:24