windows-subsystem-for-linuxxfce

xfce4-session "cannot connect display" error


I'm trying to run xubuntu-desktop on WSL as per the tutorial given by many sites. But I can't seem to connect to the display of VcXsrv and it always shows:

xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.

If I run startxfce4, it says:

/usr/bin/startxfce4: X server already running on display muhammadsalmanafzal:0.0
xrdb: Connection refused
xrdb: Can't open display 'muhammadsalmanafzal:0.0'
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.

Although, the VcXsrv window of Xlaunch is closed. Can anybody help me look for the error? What am I doing wrong? Also, when I first installed xubuntu-desktop, at the very end it said:

Errors were encountered while processing:
 blueman
E: Sub-process /usr/bin/dpkg returned an error code (1)

And then I read somewhere to remove it, so I did and reinstalled xubuntu-desktop and no error was given.


Solution

  • If you are running WSL 1 then then, you need to add following line to .bashrc in home:

    export DISPLAY=:0.0
    

    and run bash again. However, if you are running WSL 2 then you need get the IPv4 of you WSL network (since by converting to WSL 2, it becomes a network) by checking the ipconfig in Powershell and then export the relative to .bashrc

    [EDIT]

    I think after the windows update to 20H2, the above solution stopped working. So, as per the official recommendation of Ubuntu from their site, you can add the following lines in your ~/.bashrc and restart it.

     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