My preferred approach for getting a "full desktop" under WSL is to use xrdp
and then simply run Windows Remote Desktop Connection to enter the desktop manager. This avoids conflicts in hotkeys between Ubuntu and Windows. On the downside, it's a bit slower than using native WSLg.
The original question mentions both "Ubuntu Desktop" (assuming Gnome) as well as Xfce, so I'll provide steps for both. Xfce is the easier of the two, since it does not require Systemd.
Note that this updated answer has been tested on Ubuntu 22.10 with WSL2 version 1.0.3.
Xfce
sudo apt install xrdp xfce4
# If asked, select lightdm, although it probably doesn't matter
# Optionally, back up the default config
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
# Windows Pro and higher are often already running RDP on 3389
# Prevent conflicts:
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
# Prevent Wayland from being used in Xrdp
echo "export WAYLAND_DISPLAY=" > ~/.xsessionrc
# Optional, if you only have one desktop environment installed
echo startxfce4 > ~/.xsession
sudo service xrdp start
# Or, if running Systemd
sudo systemctl restart xrdp
And that's it -- You should be able to connect to your WSL Desktop using the built-in Remote Desktop Connection app. The computer to connect to will be localhost:3390
. Make sure Xorg is selected as the Session type.
Gnome Desktop
With the recent ability for WSL to use Systemd, this has become much more viable "out of the box". I'm not sure I'd "recommend it", but it's certainly possible.
First, enable Systemd. After restarting Ubuntu, ensure that Systemd is running via sudo systemctl status
The next few steps are similar to those for Xfce:
# Block ACPI features, which cause issues in WSL2, from being installed with Gnome
sudo apt-mark hold acpid acpi-support
sudo apt install ubuntu-desktop xrdp
# Optionally, back up the default config
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
# Windows Pro and higher are often already running RDP on 3389
# Prevent conflicts:
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
# Optional if you only have one desktop environment installed
echo gnome-session > ~/.xsession
Create ~/.xsessionrc
with the following:
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop
export WAYLAND_DISPLAY=
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
Then:
sudo systemctl restart xrdp
As with Xfce4, you should be able to connect to your Gnome Desktop using the built-in Remote Desktop Connection app. The computer to connect to will be localhost:3390
. Make sure Xorg is selected as the Session type.