Displaying Linux Apps in Windows (WSL)
Environment

Windows 10

Windows 11

Solution

Displaying Linux apps in Windows with Ubuntu

Running Linux GUI's in Windows requires WSL and either WSLg (Included with the latest release of WSL2) or a third-party X server (such as VcXsrv).

 

Using WSLg

Step 1. Install WSL either from the Microsoft Store or by running the following command in PowerShell:

wsl --install

If you installed from the MS store, make sure to run wsl --update then wsl --shutdown afterwards

Step 2. Enable WSL:

  1. Open Control Panel:
    • Press the Windows key + R to open the Run dialog. 
    • Type control panel and press Enter
  2. Navigate to Programs and Features: 
    • In the Control Panel, click on Programs and then Turn Windows features on or off
  3. Enable WSL and Virtual Machine Platform:
    • In the list of Windows features, check the boxes for: 
      • Windows Subsystem for Linux . 
      • Virtual Machine Platform . 
  4. Apply Changes:
    • Click the OK button. 
    • The system will search for required files and apply the changes. 
  5. Restart Your Computer:
    • Restart your computer as prompted. 
  6. Install a Linux Distribution: 
    • Once restarted, you can install your preferred Linux distribution (e.g., Ubuntu) from the Microsoft Store. 
  7. Verify Installation (Optional):
    • Open a command prompt or PowerShell and type wsl to see if WSL is installed and running.

Step 3. Confirm WSL version 2 is running

  • Open PowerShell and type the following commands:
    1. Check the version wsl --status
    2. If needed, update version wsl --set-default-version 2
    3. Check the distribution is using the correct version wsl -l -v
    4. If needed, update the distribution (replace Ubuntu with whatever distro you are using) wsl --set-version Ubuntu 2

Step 4. Run your application. See Opening Linux apps stored in Windows via Ubuntu.

 

Using a third-party X server

After installing and launching the server, you will need to set the DISPLAY environment within Ubuntu to generate any GUI elements:

For completeness, I'll also cover WSL1, even though WSL2 is the standard for modern Windows.

WSL2
  • What doesn't work in Windows 10 (and why):
    In Windows 10 with Ubuntu under WSL2, you had to use a third-party X server to run graphical apps. Since that X server is running in Windows (rather than Ubuntu), it's on a separate network and needs an IP address.
    On Windows 10, the following would not work:
    export DISPLAY=:0.0

    # or export DISPLAY=:0
  • Windows 10 using mDNS with WSL's DNS Resolver:
    I usually use and recommend:
    export DISPLAY=$(hostname).local:0
    This uses mDNS to obtain the correct address.
    Note that this assumes that you are using the built-in WSL DNS resolver. If you override this with your own DNS settings, it probably won't work since your DNS server probably won't know the correct IP address for your Windows host.
  • Windows 11 using WSLg:
    Under Windows 11, WSL2 can run GUI applications using the WSLg feature. It runs in the same network space as WSL itself, so under Windows 11, we're back to the following being the correct DISPLAY setting:
    export DISPLAY=:0
    Note that this is set for you automatically in your Ubuntu/WSL2 session by the WSL /init, so there shouldn't be any reason to set it manually except in some special circumstances.
WSL1
  • For both Windows 10 and 11:
    Under WSL1, Ubuntu itself is running under the same network as Windows, so in that case, you'll use:
    export DISPLAY=:0
    Note that you will need a third-party X server with WSL1, regardless of whether you are running Windows 10 or 11. WSLg is only supported under WSL2.

Opening Linux apps stored in Windows via Ubuntu

You must traverse the directory to the Windows drive in Ubuntu before opening any files contained therein. Use the following command from your home folder:

cd /mnt/< windows drive letter>
Additional Information