Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSL 2: Run Graphical Linux Desktop Applications from Windows 10 Bash Shell "Error E233: cannot open display" [closed]

How to run graphical Linux desktop applications from Windows 10’s Bash Shell?

First, I installed Windows Subsystem for Linux (WSL) following steps as shown in here as follows:

(1) Installed Windows 10 Pro Insider Preview Build 19619.

(2) Installed Ubuntu Linux distribution.

(3) Changed the distribution version from WSL 1 to WSL 2.

Second, to enable graphical Linux desktop applications from Windows 10’s Bash Shell, I followed the following steps as shown here as follows:

(4) I installed an X Server that is Xming

(5) Installed graphical GTK-based vim editor as test using:

sudo apt-get install vim-gtk

(6) Set my display environment variable

export DISPLAY=:0

(7) Launch an Application

gvim

However, this did not lunch the application and I got the following error:

E233: cannot open display Press ENTER or type command to continue E852: The child process failed to start the GUI Press ENTER or type command to continue 

Any idea why this error is occurring?

like image 626
ASE Avatar asked May 17 '20 23:05

ASE


People also ask

How do I enable GUI in WSL2?

Linux GUI apps are installed using the sudo apt-get install command inside the WSL distro. Once the GUI app is installed, you can launch it from the Start menu or use a command. The feature requires installing WSL2 with the wsl --install command on build 21364 or higher.

Does X11 support WSL?

Windows Subsystem for Linux (WSL) now supports running Linux GUI applications (X11 and Wayland) on Windows in a fully integrated desktop experience.

How do I fix WSL2 Internet problems?

Under the "Advanced network settings" section, click the Network reset option. Click the Reset now button. Click the Yes button. After you complete the steps, the computer will restart automatically, and on reboot, you should now be able to connect to the internet.


1 Answers

The networking subsystem in WSL2 is different than the used in WSL1. You must consider the differences to access networking apps running on Windows and on Linux:

  • In WSL1, Linux uses the same IP addresses than the Windows host, then, you can access the applications using localhost or 127.0.0.1
  • In WSL2, Linux runs on a lightweight virtual machine and has a different IP address. To access networking apps running on the Windows Host you must use the Windows IP address.

Checking the IP address of the Windows host

There are many ways to determine the IP addresses in the Windows host. You may run the following commands in your WSL Linux:

  • cat /etc/resolv.conf shows the IP address of the eth0 interface in Windows
  • ipconfig.exe shows the all the IP configuration in the Windows host
  • route.exe print shows the network routing configuration in the Windows host

Setting the DISPLAY variable for WSL2

Based on the Microsoft documentation, you may set the DISPLAY variable checking the nameserver in the /etc/resolv.conf file. (@fqquiner and @VPraharsha already mentioned this)

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

However, I had problems using this solution, probably because I use my notebook with a WiFi connection and multiple virtual networks. Instead of the previous solution, I determine the Windows IP address using route.exe and checking the interface used in the default gateway.

export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0 

Setting the DISPLAY variable in the .profile

You may set the DISPLAY variable in your ~/.profile file. I used the following code:

# set DISPLAY to use X terminal in WSL # in WSL2 the localhost and network interfaces are not the same than windows if grep -q WSL2 /proc/version; then     # execute route.exe in the windows to determine its IP address     DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0  else     # In WSL1 the DISPLAY can be the localhost address     if grep -q icrosoft /proc/version; then         DISPLAY=127.0.0.1:0.0     fi  fi 
like image 74
Jaime Avatar answered Sep 22 '22 15:09

Jaime