70

How can I run graphical Linux desktop applications from the command line of Windows Subsystem for Linux (WSL)?

First, I installed WSL 2 following these steps on how to install Linux on Windows with WSL :

  1. I installed Windows 10 Pro Insider Preview Build 19619.

  2. I installed the Ubuntu Linux distribution.

  3. I changed the distribution version from WSL 1 to WSL 2.

Second, to enable graphical Linux desktop applications from the Bash shell of WSL, I followed these steps on how to run graphical Linux desktop applications from Windows 10’s Bash shell :

  1. I installed an X Server that is Xming.

  2. As a test I installed the graphical GTK-based editor Vim :

    sudo apt-get install vim-gtk

  3. I set my display environment variable :

    export DISPLAY=:0

  4. I tried to launch the application :

    gvim

    However, this did not launch the application. I got the following errors :

    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?

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
ASE
  • 1,702
  • 2
  • 21
  • 29
  • Did you try to stop and restart your cli ? – Dan M. CISSOKHO Sep 25 '20 at 08:23
  • 3
    Most answers here are from before this was a completed feature in WSL2. It not works quite well "out of the box": https://stackoverflow.com/a/68416242/4612476 – Cameron Tacklind Jul 21 '21 at 22:15
  • 4
    Wouldn't this question work better on Super User? – spicy.dll Oct 07 '21 at 15:30
  • 4
    Very valid question and many members seem to agree. Also very good answer with lots of upvotes. And yet, `closed` by an *experienced* member... that's why I try to avoid SO as much as possible... – Raf Feb 03 '22 at 09:59
  • @Raf It's what happens when they go to meta with a one sided account of what happened to get the mob going. – Cameron Tacklind Dec 06 '22 at 22:34
  • It's important to note here that "It is highly recommended to use the Microsoft Store version of WSL" and NOT to install via the command line. I could not get wsl GUI's to work until I reinstalled from the store rather than installing via wsl --install. github.com/microsoft/wslg – Edward Pescetto Jan 25 '23 at 15:23

8 Answers8

127

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
Jaime
  • 5,435
  • 2
  • 18
  • 21
  • 28
    For me using the `route.exe` was the solution – hitautodestruct Mar 04 '21 at 09:17
  • In addition, see @fquinner's answer. You must also open TCP port 6000 to your WSL's IP address. For example, if your WSL is on 172.23.80.1, add an inbound firewall rule to allow traffic from 172.23.80.0/12. See Instructions: https://github.com/cascadium/wsl-windows-toolbar-launcher/blob/master/README.md#troubleshooting. – intotecho Jun 03 '21 at 04:04
  • 3
    Thank you for the answer. Using /etc/resolv.conf works for me, but route.exe does not. I don't know how to format this, but: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 192.168.86.1 192.168.86.51 35 ... 172.22.224.1 255.255.255.255 On-link 172.22.224.1 5256 The 172 address is the correct one (at least it's the one that works). – mzimmers Jun 24 '21 at 22:15
  • 6
    If still doesn't work, check out my step by step answer on GitHub: https://github.com/microsoft/WSL/issues/4106#issuecomment-876470388 – Kevin Patel Jul 08 '21 at 14:11
  • Thanks @KevinPatel for the instructions to configure the `vcxsrv` in windows 10. @KevinPatel and @shortpoet (in Github) are using the above solution to find the `DISPLAY` value. – Jaime Jul 12 '21 at 02:25
  • using the `route.exe` method worked for me the classic `resolve.conf` method did not work – d-man Aug 17 '21 at 01:50
  • How are you guys running `route.exe` from Linux/WSL?? I get `run-detectors: unable to find an interpreter for /mnt/c/Windows/system32/route.exe` – Marc Aug 28 '21 at 10:35
  • 3
    For some reason, running route.exe in my .zshrc file causes the entire terminal to hang iff it is opened in a Linux directory. I ended up needing to cd into a Windows directory before running route.exe: `export DISPLAY=$(cd /mnt/c && route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0` – Christian Sep 05 '21 at 08:22
  • don't forget to restart the distribution "wsl --shutdown " – Behrouz Seyedi Mar 23 '22 at 20:53
  • I also had to cd into a Windows directory in order for the "route.exe" option to actually work. – kotozna Apr 25 '22 at 00:31
  • `export DISPLAY=$(route.exe print | grep 0.0.0.0 | head -1 | awk '{print $4}'):0.0` worked for me – Humberd May 12 '22 at 09:25
  • Tiny improvement on the route solution: `export DISPLAY=$(route.exe print | awk '/0.0.0.0/{print $4; exit}'):0.0` works nicely and only requires awk, no `grep` or `head`. Shaves a couple of milliseconds off startup time when you stick this into your `.profile`... ;] – HerbCSO Aug 10 '22 at 14:14
  • Oh, man, Windows 10 - WSL 2...setting the second DISPLAY variable in your "Setting the DISPLAY variable for WSL2" section made it for me. THANKS SO MUCH! – evaldeslacasa Feb 28 '23 at 20:06
38

Had the same problem so I tried these other suggestions but what ended up working was allowing vcxsrv through the public firewall. I know you're not using vcxsrv but perhaps it's the same problem for you too.

Install VcXsrv then enable public firewall like these pictures. Open Windows Defender Firewall with Advanced Security using wf.msc at command prompt. Then allow connections like in these pictures.

Double click then allow each of the public profiles for VcXsrv

[Allow the connection in VcXsrv firewall properties2

Then run VcXsrv from this guide for Windows 10 WSL2

Run VcXsrv by adding -ac addition parameter or type this at command prompt "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -multiwindow -clipboard -wgl -ac

Then type this into your WSL2 terminal

export DISPLAY_NUMBER="0.0"
export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):$DISPLAY_NUMBER
export LIBGL_ALWAYS_INDIRECT=1
# OPTIONAL Set the keyboard layout to US
setxkbmap -layout us
setsid emacs
exit
Saj
  • 781
  • 8
  • 7
14

Updating my answer with more recent information than was available at the time the question was originally asked. Keep in mind, though, that because this question is closed and off-topic here on Stack Overflow, eventually the answers here may become stale, since no new answers can be posted. I recommend checking Super User or Ask Ubuntu for more on-topic and still-open questions on this topic. It's always possible for a better answer to come along in the future.

Some existing questions for reference:

With that in mind, the information below is currently mostly copied from my Super User answer to the question above.


There are (at least) three options:

  • With the release of WSL 1.0.0 (WSL via Microsoft Store application), both Windows 10 and Windows 11 users have full access to WSLg, which allows Linux GUI applications (X or Wayland) to run directly on WSL2 with no additional configuration. Prior to 1.0.0, this feature was limited to Windows 11 users.

    Windows 10 users will need to be on a build ending in .2311 or higher, which currently means installing KB5020030. If the final four digits of your build number are lower than 2311, make sure your Windows is up-to-date, then find KB5020030 in the Optional Updates.

    Once on an up-to-date Windows 10 or Windows 11 system, either:

    Install WSL from the Microsoft Store or ...

    wsl --install
    # or, if already installed
    wsl --update
    # confirm 1.0.0 or later via:
    wsl --version
    
  • A legacy alternative is the one that harrymc offers of installing a third-party X server. I won't repeat the information on how to do so since it's already covered in that answer, although I will say that export DISPLAY=$(hostname).local:0 will typically work, and is more concise. This uses mDNS as I go into detail on in this answer.

  • Finally, if you want to run a Linux desktop under WSL, you might want to consider RDP. You can install xrdp and just access a Linux desktop using Windows Remote Desktop connection. See my steps for doing so in this Ask Ubuntu answer. Note that only xfce is really necessary, although the answer includes more detail on running something more complex like Gnome Desktop.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • This solution works for me. But a bit slower than the using VcXsrv in Windows. – Yu Shen Oct 30 '21 at 13:38
  • It's important to note here that "It is highly recommended to use the Microsoft Store version of WSL" and NOT to install via the command line. I could not get wsl GUI's to work until I reinstalled from the store rather than installing via wsl --install. https://github.com/microsoft/wslg – Edward Pescetto Jan 25 '23 at 15:22
  • 1
    @EdwardPescetto Interesting, `wsl --install` is supposed to use the Store to install, but "behind the scenes". But I'll update the answer with that. Thanks for the info! – NotTheDr01ds Jan 25 '23 at 15:32
10

Adding to fquinner's answer,

Your DISPLAY env variable should be set as export DISPLAY=X.X.X.X:0 to use the Windows host's IP address as WSL2 and the Windows host are not in the same network device, where X.X.X.X is the IP address

and your IP address is listed in resolv.conf against the nameserver ($ cat /etc/resolv.conf)

or simply export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0" to load the correct IP address automatically. Additionally, you can add this to .bashrc or .zshrc (If you use Zsh)

VPraharsha
  • 386
  • 2
  • 8
6

There's a troubleshooting section here for debugging X11 on wsl2:

https://github.com/cascadium/wsl-windows-toolbar-launcher/blob/master/README.md#troubleshooting

Port forwarding is not the same as WSL1 - your Linux services may be accessible via localhost for windows, but the reverse is no longer true.

So you need to use the internal IP of your windows host and tweak the firewall to allow the WSL network through.

fquinner
  • 548
  • 5
  • 16
  • How to tweak the firewall? I tried following the instructions at https://github.com/cascadium/wsl-windows-toolbar-launcher/blob/master/README.md#user-content-firewall-rules but I don't get any pop-up from the firewall. It just hangs. DISPLAY looks reasonable to me. – BobDoolittle Aug 21 '22 at 23:32
4

enter image description here The following instructions were copied and pasted from an article I wrote but it lost the original formatting, links, and screenshots:

Source: How to Install Ubuntu Desktop with a Graphical User Interface in WSL2


Download VcXsrv: Visit the official website Click "Download"


Install VcXsrv: Open "vcxsrv-64.1.20.8.1.installer.exe" Click "Next" Click "Install" Click "Close"


Allow Access to VcXsrv: Check "Private Networks" Click "Allow Access"


Open PowerShell: Press "⊞ Windows" Enter "PowerShell" into the search bar Right-click "Windows PowerShell" Click "Run as Administrator"


Open WSL2: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

wsl


Install Ubuntu Desktop: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt --yes install ubuntu-desktop


Set the Username Variable: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

username=$(wslvar USERNAME)


Create the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

mkdir --parents /mnt/c/users/$username/.ubuntu/


Open the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

cd /mnt/c/users/$username/.ubuntu


Download Linux Software Repository for Microsoft Products: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

Ubuntu 20.04: wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb --output-document packages-microsoft-prod.deb Ubuntu 18.04: wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb --output-document packages-microsoft-prod.deb


Install Linux Software Repository for Microsoft Products: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo dpkg --install packages-microsoft-prod.deb


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install APT Transport for HTTPS: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes apt-transport-https


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install .Net: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes dotnet-sdk-5.0


Add Arkane Systems to the Source List Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo sh -c 'echo "deb [trusted=yes] https://wsl-translinux.arkane-systems.net/apt/ /" > /etc/apt/sources.list.d/wsl-translinux.list'


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install Genie: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes systemd-genie


Create the Sudoers File: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/genie" | sudo EDITOR="tee" visudo --file /etc/sudoers.d/$USER


Create the Desktop Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# CREATE BASH SCRIPT

# Store block of text with here document
create_bash_script=$(cat << end_of_string

# Define necessary environment variables
export DISPLAY="\$(cat /etc/resolv.conf | grep nameserver | awk '{ print \$2 }'):1.0"
export DESKTOP_SESSION="ubuntu"
export GDMSESSION="ubuntu"
export XDG_SESSION_DESKTOP="ubuntu"
export XDG_CURRENT_DESKTOP="ubuntu:GNOME"
export XDG_SESSION_TYPE="x11"
export XDG_BACKEND="x11"
export XDG_SESSION_CLASS="user"
export XDG_DATA_DIRS="/usr/local/share/:/usr/share/:/var/lib/snapd/desktop"
export XDG_CONFIG_DIRS="/etc/xdg"
export XDG_RUNTIME_DIR="\$HOME/xdg"
export XDG_CONFIG_HOME="\$HOME/.config"
export XDG_DATA_HOME="\$HOME/.local/share" 
export XDG_CACHE_HOME="\$HOME/.cache"
export XDG_DESKTOP_DIR="\$HOME/Desktop"
export XDG_DOCUMENTS_DIR="\$HOME/Documents"
export XDG_DOWNLOAD_DIR="\$HOME/Downloads"
export XDG_MUSIC_DIR="\$HOME/Music"
export XDG_PICTURES_DIR="\$HOME/Pictures"
export XDG_PUBLICSHARE_DIR="\$HOME/Public"
export XDG_TEMPLATES_DIR="\$HOME/Templates"
export XDG_VIDEOS_DIR="\$HOME/Videos"

# Start desktop environment
gnome-session

end_of_string
)

# Store username environment variable in lowercase
username=$(wslvar USERNAME | awk '{ print tolower($0) }') &&

# Save block of text in bash file
echo "${create_bash_script}" > "/mnt/c/users/$username/.ubuntu/02_start_desktop.sh"


Download the Shortcut Images: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

wget https://assets.ubuntu.com/v1/9fbc8a44-circle-of-friends-web.zip


Unzip the Shortcut Images: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

unzip -o 9fbc8a44-circle-of-friends-web.zip


Create the Shortcut Icon: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

convert -resize 64x64 ./circle-of-friends-web/png/cof_orange_hex.png ubuntu.ico


Exit WSL2: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

exit


Create the VcXsrv Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# RELOAD VCXSRV SCRIPT

# Store username environment variable in lowercase
$username = $env:username.tolower()  

# Store block of text with here-string
$reload_vcxsrv_script = @"

# Stop vcxsrv proccess that contains "1.0" in the program window title
get-process vcxsrv | where { `$_.mainwindowtitle -like "*1.0*" } | stop-process

# Start vcxsrv process in a large program window on display number one
start-process "c:\program files\vcxsrv\vcxsrv.exe" -argument ":1 -ac -nowgl -multimonitors -dpms"

"@

# Save block of text in powershell file
echo "${reload_vcxsrv_script}" > $env:userprofile/.ubuntu/reload_vcxsrv.ps1


Create the Ubuntu Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# CREATE VISUAL BASIC SCRIPT

# Store username environment variable in lowercase
$username = $env:username.tolower()           

# Store block of text with here-string
$create_vbs_script = @"

' Run PowerShell script in background
set application = createobject("shell.application")
application.shellexecute "powershell", "-file c:\users\admin\.ubuntu\01_reload_vcxsrv.ps1", "", "", 0

' Allow PowerShell script to complete
wscript.sleep 3000

' Run Bash script in background
set shell= createobject("wscript.shell")
shell.run "wsl sudo genie -c bash /mnt/c/users/admin/.ubuntu/02_start_desktop.sh", 0

"@

# Save block of text in bash file
echo "${create_vbs_script}" > $env:userprofile/.ubuntu/03_start_ubuntu.vbs


Create the Shortcut Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# Store block of text with here-string
$create_shortcut_script = @"

# Define location variables
`$shortcut_location = "`$env:userprofile\.ubuntu\Ubuntu.lnk"
`$program_location = "`$env:userprofile\.ubuntu\03_start_ubuntu.vbs"

# Create shortcut
`$object = new-object -comobject wscript.shell
`$shortcut = `$object.createshortcut(`$shortcut_location)
`$shortcut.targetpath = `$program_location
`$shortcut.iconlocation = "`$env:userprofile\.ubuntu\ubuntu.ico"
`$shortcut.save()

"@

# Save block of text in powershell file
echo $create_shortcut_script > $env:userprofile/.ubuntu/04_create_shortcut.ps1


Open the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

cd c:\users\admin\.ubuntu


Create the Shortcut: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

powershell.exe -file .\04_create_shortcut.ps1


Open the Directory in Explorer: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

explorer .


Launch the Ubuntu Desktop: Double-click the "Ubuntu" shortcut


Open Terminal: Click "Activities" in the top-left corner Enter "Terminal" into the search bar Click "Terminal"


Disable the Screen Lock: Copy the command from below these instructions Paste the command into Terminal Press "Enter"

gsettings set org.gnome.desktop.screensaver lock-enabled false


Install the Snap Store: Copy the command from below these instructions Paste the command into Terminal Press "Enter"

sudo snap install snap-store


  • 16
    All in 27 simple steps! – Entalpi Feb 14 '21 at 09:12
  • This worked perfectly for me, but I get logged in to Ubuntu as root. Is that what you would expect? I followed the instructions above, except I always used my own username (in the instructions for creating the Visual Basic script, there are a two places where the "admin" user is used). Is there any way to get logged in under my own username instead of root? – John Mar 31 '21 at 06:20
  • @Entalpi Yeah, haha. – david-littlefield Mar 31 '21 at 21:37
  • @John Try removing the sudo from the following line in 03_start_ubuntu.vbs: shell.run "wsl sudo genie -c bash /mnt/c/users/admin/.ubuntu/02_start_desktop.sh", 0 – david-littlefield Mar 31 '21 at 21:38
  • 1
    @TheAltruist Removing the sudo fixed it - I now get logged in under my own username. Thanks! – John Apr 01 '21 at 00:58
  • @John Awesome, glad you got it working! – david-littlefield Apr 02 '21 at 03:07
  • @TheAltruist - After successfully using this for several months, I tried to set it up on another machine and can't get it to work. When I click on the shortcut to start Ubuntu, it brings up a window but it is completely blank. When I kill the window, VcXsrv gives me a message: "Exiting will close all screens running on this display. There are currently 0 clients connected". If there are no clients connected, I assume something basic has gone wrong. Any ideas? – John Sep 18 '21 at 23:57
  • @John - The firewall could be blocking connections to the display server. There have also been some changes to the process since this post. You can see the changes here: https://medium.com/p/71f4b78431a4 – david-littlefield Sep 19 '21 at 07:32
  • @TheAltruist - thanks, runs now with firewall rules updated. One other question - how do you copy and paste between windows and ubuntu? – John Sep 20 '21 at 00:15
  • Why should any of this be necessary? Ubuntu WSL is supposed to be fully functional and ship with an X server of its own. – BobDoolittle Aug 21 '22 at 23:34
  • @BobDoolittle, This process adds WSL support for Linux-based distributions with a graphical user interface. WSL only supports applications with a graphical user interface. – david-littlefield Aug 23 '22 at 04:21
  • @david-littlefield I still don't get it. The only way Linux applications can display graphics is via Xlib which talks to the Linux X server. So it's all-or-nothing. Either Ubuntu WSL supports graphics, in which case all applications/desktops can use Xlib to display graphics, or it doesn't and no applications/desktops can display graphics. There is no "applications can display graphics but the distro can't". – BobDoolittle Oct 07 '22 at 20:44
  • @BobDoolittle This was written before WSL included X Server by default. At the time, there wasn't a one-stop tutorial that covered how to use WSL with a graphical user interface (GUI). So, it might not be necessary anymore, or maybe just the part about installing X Server, but I haven't tried it yet. Were you able to get the Ubuntu Desktop GUI to work without going through these steps? – david-littlefield Oct 09 '22 at 23:35
-2

In case anyone didn't know, there is an easier way. In 2021, Microsoft gave us WSLg.

Windows 11 and Windows 10 22H2 (build 19044.2311 or later) include WSLg.
Drivers for vGPU (Intel AMD Nvidia) are recommended.

WSLg is not compatible with WSL1. New WSL2 instances will basically just work.
Older WSL2 systems will need to be updated once:

  1. In administrative PowerShell: wsl --update
  2. wsl --shutdown to force a restart of the WSL

Don't forget to remove any other modifications to $DISPLAY that you may have made!

Screenshot of WSLg running on Windows 11

Cameron Tacklind
  • 5,764
  • 1
  • 36
  • 45
  • 4
    I have tried this, and it doesn't just work. – Eric Hansen Jul 21 '21 at 18:39
  • 1
    @EricHansen Sounds like you broke something else. I have now successfully done this on 3 different Windows machines (10 and 11). Did you check your version? Is something else setting display to something other than `:0`? I'm sure the WSL team would love to hear about your issues because they are trying to make this work well. – Cameron Tacklind Jul 21 '21 at 21:48
  • 1
    I'm on Windows 11 Pro 10.0.22000 Build 22000 and WSL version 2. It works today. It didn't yesterday. Did I restart in between? Yes. Did Windows do an update? I don't think so, but I must be wrong? Who knows. – Eric Hansen Jul 22 '21 at 22:25
  • 3
    @CarlosRafaelRamirez This absolutely works on Windows 10. Also, many people end up here trying to get WSLg working and then go down a long rabbit hole, like I did, that is completely unnecessary. – Cameron Tacklind Aug 06 '21 at 22:09
  • 2
    @CameronTacklind tell me which released not insider version of Windows 10 runs WSLg? – Carlos Rafael Ramirez Aug 07 '21 at 22:42
  • @CarlosRafaelRamirez Just match the requirements. If you want to use a non-insiders version, yes, go ahead, use the older ways. – Cameron Tacklind Aug 07 '21 at 22:49
  • 2
    @CameronTacklind Until you see a release version of Windows 10 with WSLg (and it won't happen) the older ways as you mention are not older at all. You cannot say that other methods are defunct because you are using a preview version of Windows. People will come to your answer thinking that their Windows 10 released on October 2021 will work and it won't. Put in the title (Insider version required) – Carlos Rafael Ramirez Aug 07 '21 at 23:17
  • @CameronTacklind The current release is listed on this official page: https://learn.microsoft.com/en-us/windows/release-health/release-information, you are using a beta version intended for developers despite you want to call it "current". It only confuses users. – Carlos Rafael Ramirez Aug 19 '21 at 09:19
  • 2
    @CameronTacklind Hopefully you don't consider my latest edit "over-zealous." I hope we can agree that *currently*, some disclaimer is needed that this only works on **beta/insider**, and Microsoft does *not* recommend Dev Channel for daily use. – NotTheDr01ds Aug 19 '21 at 21:17
  • 1
    @CarlosRafaelRamirez Agreed on most all of this, but can you point me to the statement regarding there being no plan to release it for the next Windows 10/WSL update? I hadn't seen a definitive statement either way, and I really expected/expect Windows 10 versions to continue to get WSL updates for a few more years. – NotTheDr01ds Aug 19 '21 at 21:19
  • @NotTheDr01ds In my humble opinion, calling out such differences in versions of Windows is beyond the scope of this answer. Noting that the "Insider build of Windows 10" (or 11) was required seemed wholly sufficient to me. The way I had it also seems like the answer would stay true as the landscape evolved. I, also, personally, disagree that the other answers here are "good approaches". They certainly seem to work and are therefore worthwhile, but, imho, "good" is rather subjective, and I would not be happy with those solutions. – Cameron Tacklind Aug 19 '21 at 21:47
  • 2
    @CameronTacklind I feel it's *required* in order to be a responsible answer. If you propose a solution that requires Insider Dev Channel on Windows 10, then it needs to cover the caveats. Microsoft does *not* recommend Dev Channel builds for daily use. The other answers *are* good (even the correct) approaches as of today for those not willing to run an unstable OS release. – NotTheDr01ds Aug 20 '21 at 00:12
  • @NotTheDr01ds That feels like information that would belong in the comments, or as an asterisk. Not a block of text at the start of the answer that, imho, makes it less approachable. – Cameron Tacklind Aug 20 '21 at 06:15
  • @CameronTacklind https://github.com/microsoft/wslg/issues/347 here is the statement. I was expecting to have these back ported to Windows 10 mainly because the CPU requirements of Windows 11. In fact any 20000 insider version is considered now exclusively part of Windows 11. Windows 10 stayed and will remain in 1904x sadly. They need to backport too many stuff begining with the new device driver architecture, that is one of the key points of Windows 11. – Carlos Rafael Ramirez Aug 20 '21 at 13:31
  • 2
    @CarlosRafaelRamirez Thanks for the link. Just a heads-up that you tagged Cameron in that comment, but it was actually me who asked that question :-) Sad to hear that, but at least we can still use `xrdp` on individual distros with Windows 10/WSL. I won't be able to update all my computers to Windows 11, that's for sure. – NotTheDr01ds Aug 23 '21 at 09:32
  • I am on the new WSL2 but it does not "just" work. I cannot open any GUIs. – Durga Swaroop Sep 01 '21 at 08:03
  • 1
    @DurgaSwaroop What version & build of Windows are you running? What is your `$DISPLAY` set to? – Cameron Tacklind Sep 03 '21 at 19:31
  • 7
    This answer is being discussed on [meta](https://meta.stackoverflow.com/questions/412056). Please continue discussion about the appropriateness of the formatting in this answer on the meta post, instead of as comments on the answer. – cigien Oct 07 '21 at 03:55
  • 2
    October 2021 called to say that WSLg will be available in Win10's November 21H2 update (yes, build 22000+) and I just installed Win11 and using WSLg was easy peasy, so now as of date this solution works so it should not be downvoted. Although GWSL seems to work better since it's X-based, unlike WSLg which is Wayland-based, but it's good to have an official alternative :) – DARKGuy Oct 25 '21 at 08:02
  • On Windows 11 I am now using WSLg. This is the version information displayed: wsl --version WSL version: 0.50.2.0 Kernel version: 5.10.74.3 WSLg version: 1.0.29 Windows version: 10.0.22000.434 My PC no longer is enrolled in the Windows Preview program. – D. Charles Pyle Jan 18 '22 at 15:15
  • 1
    If you have issue, follow this guide to debug and diagnose. It works for me. https://github.com/microsoft/wslg/wiki/Diagnosing-%22cannot-open-display%22-type-issues-with-WSLg – Felix Jan 22 '22 at 06:20
-3

2022 update. simplest way, works without 3rd party apps

  1. update your Windows to 22H2 or to W11, reboot
  2. do wsl --update, reboot

original answer

This worked for WSL1, for WSL2 set appropriate IP adress

  1. install xming server
  2. on WSL run export DISPLAY=localhost:0.0

enter image description here

Alkor
  • 137
  • 7