14

I'm running a Windows 10 computer and have recently installed Windows Subsystem for Linux. This generally creates a single terminal with no "display" environment. It seems that Tmux can be used to get several terminals, but this doesn't let you use any sort of graphical display.

I'd like to open a Linux browser, such as Firefox, through Windows Subsystem for Linux.

I tried the suggestions here, but I just get the error:

no DISPLAY environment variable specified
NotTheDr01ds
  • 28,025

7 Answers7

8

See Ubuntu wiki Running Graphical Applications.

You need to install on Windows an X-server to be launched from Windows to be used by WSL graphical applications.

You may use any of X410, VcXsrv, MobaXTerm, Cygwin/C, Xming, Cygwin X, vcXsrv.

If graphical applications can't connect to the running X server automatically paste the following commands to the terminal before starting the applications or set them on every login by adding them to ~/.bashrc:

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

Another useful article is Running Graphical Programs on Windows Subsystem on Linux.

harrymc
  • 498,455
6

Adding an answer with more recent information than was available at the time the question was originally asked, primarily because I'm linking to this question/answer for other duplicates (here and on Stack Overflow, where it's general an off-topic question).

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, you can either install WSL from its Microsoft Store page 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
  • 28,025
6

Remove all export DISPLAY settings in your startup files!

It's not needed anymore.

With recent WSL (Windows 10 Build 19044+ or Win 11), the system takes care of that.

I repeat.

You do no longer need to export the DISPLAY variable!

Prior to reading the official documentation, linked in MOMO's answer, I had tried all the fancy ways of getting the DISPLAY value automatically set posted by others, and nothing worked.

Backstory

I, and many with me, use non-default name servers, so I can't use that trick to refer to my local system. Instead I have a static value for IPv6 localhost in /etc/hosts.

# This is to always have a named host address for servers on WSL, like sshd
# Usually I use 127.0.0.1 instead.
::1     wsl

And the same in Windows c:\Windows\System32\drivers\etc\hosts

Then I had set the DISPLAY variable in ~/.bashrc like this.

export DISPLAY=wsl:0.0

When testing both thunderbird and mousepad start fine.

But if I tried to start firefox/firefox-esr I got failed access to DISPLAY.

$ firefox-esr
Error: cannot open display: wsl:0.0

Basically, thunderbird never cared what DISPLAY was set to. Perhaps that is why it worked for me. It started even back when the variable was set to the wrong IP.

But, now, with no DISPLAY variable manually set, firefox works great!

Information about my Windows 10 system.

$ uname -a
Linux pappa 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 \
UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy

> wsl --version WSL-version: 1.0.3.0 Kernelversion: 5.15.79.1 WSLg-version: 1.0.47 MSRDC-version: 1.2.3575 Direct3D-version: 1.606.4 DXCore-version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows: 10.0.19045.2364

> wsl -l -v NAME STATE VERSION

  • Ubuntu Running 2 Debian Stopped 2

NVIDIA Geforce GTX 1070, driver 527.56

Apps that I tested.

$ thunderbird --version
 Thunderbird 102.6.1

$ mousepad --version Mousepad 0.5.8

$ firefox --version Mozilla Firefox 108.0.1

$ firefox-esr --version Mozilla Firefox 102.6.0esr

Even something heavy like GIMP runs fine.

$ gimp --version
GNU Image Manipulation Program version 2.10.30

And finally...

$ set | grep DISPLAY
DISPLAY=:0
WAYLAND_DISPLAY=wayland-0
2

I struggled with this same issue and couldn't get it working with any of the fixes here. Unsurprisingly, following the Microsoft Documentation on Running GUI apps in the Windows Subsystem for Linux did the trick.

First step is to install a GUI driver according to your GPU:

Then, open up a CommandPrompt (or PowerShell) and run the following commands.

Fresh install

If you have no prior WSL installation, run wsl --install.
You will need to restart your machine to finish installation, after which installation will resume. Once WSL is launched, you will be prompted for a username and password. You will need that password anytime you need to sudo.
If you still haven't installed any linux distro, check out this other guide.

Existing WSL install

If you already have WSL installed, first close any open instances of WSL.
Run wsl --update.
In order to restart WSL, run wsl --shutdown.

Running GUI apps

Once you've installed/updated WSL, open Linux by running wsl from a command prompt. One final step, run: sudo apt update. You're done!

To verify run (or install and run) any app that requires a GUI.

Running Firefox

sudo apt install firefox
firefox

Hope this helps.

NotTheDr01ds
  • 28,025
MOMO
  • 21
1

sudo nano /etc/wsl.conf

and put in it:

[boot]
systemd=true

if one omit this detail we get the error !! :

error: cannot communicate with server: Post "http://localhost/v2/snaps/firefox": dial unix /run/snapd.socket: connect: no such file or directory

when

sudo snap install firefox

install-ubuntu-on-wsl2-on-windows-11

-1

I can't comment as this is a new account and I did not have enough reputation. But I would like to adhere to MOMO answer. Thank you!! Remember to wsl --update

I have similar issue as @tolache

When I run firefox, I get Command '/usr/bin/firefox' requires the firefox snap to be installed. Please install it with: snap install firefox.

If I run snap install firefox it fails with error: cannot communicate with server: Post "http://localhost/v2/snaps/firefox": dial unix /run/snapd.socket: connect: no such file or directory.

I'm on Windows 10. I have my GPU drivers installed. Following this thread I realised my /etc/wsl.conf is already configured.

[boot]
systemd=true

But, when I run systemctl is-system-running, it returns offline.

And if I run wsl --version in CMD/Powershell, it returns Invalid command line option: --version

Again, following this thread, I realised the resolution is as well wsl --update

So, if anyone has same situation as me, could kindly try wsl --update first, and followed by wsl --shutdown. Then only wsl -d DistroName to start your Linux Distro in WSL2.

And everything is working fine now. wsl --version is working systemctl is-system-running is showing Running. And I can sudo snap install firefox and launch the browser with issuing firefox command.

Thank you.

jas99
  • 101
-2

We recommended called gwsl better than old wsl did.