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?
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.
Windows Subsystem for Linux (WSL) now supports running Linux GUI applications (X11 and Wayland) on Windows in a fully integrated desktop experience.
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.
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:
localhost
or 127.0.0.1
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 Windowsipconfig.exe
shows the all the IP configuration in the Windows hostroute.exe print
shows the network routing configuration in the Windows hostBased 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
.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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With