Note
If you want a more complete experience and already tried the Xvnc tutorial, maybe you should try the WSLg (Xwayland) instead.
Warning
This is a work in progress tutorial. Things done here may break existing functionality, so be careful!
In this tutorial, we will install and use a full GNOME Desktop environment in WSL2, without any external software. The only requirement is a working WSLg installation. At the moment, the instructions are only for Ubuntu (20.04, 22.04 and 24.04) distros and GNOME, but you can request me to test other distros and desktop environments.
- No fullscreen support
- No complete desktop support (with Display Manager)
- No support to clipboard (copy & paste) from/to Windows
-
Open a Ubuntu (20.04, 22.04 or 24.04) terminal. First of all, we need to make sure everything is up to date.
sudo apt update sudo apt upgrade
-
WSL doesn't install the app store by default, so we can install it manually (or you can skip this step if you don't need it).
sudo snap install snap-store
-
Now we can install the required packages. This may take a long time, so be patient.
sudo apt install ubuntu-desktop acpi-support-
sudo apt install ubuntu-desktop
Important
Note the minus sign (-) after the package acpi-support
. This is necessary because it will be installed by default and installing it will render your distro almost unusable (see microsoft/WSL#10059), so we will tell apt
to not install it.
-
Now we have everything installed, we must configure some things before using the GNOME Shell. First, we need to deactivate the GDM service, because unfortunately it doesn't work with WSLg yet (at least I didn't figure it out how to make it work).
sudo systemctl mask gdm.service
-
Now we need to fix the directory
/tmp/.X11-unix/
, because it's mounted as read-only by default. We will create a newsystemd
unit.sudo systemctl edit --full --force wslg-fix.service
-
Paste the code below in the editor.
[Service] Type=oneshot ExecStart=-/usr/bin/umount /tmp/.X11-unix ExecStart=/usr/bin/rm -rf /tmp/.X11-unix ExecStart=/usr/bin/mkdir /tmp/.X11-unix ExecStart=/usr/bin/chmod 1777 /tmp/.X11-unix ExecStart=/usr/bin/ln -s /mnt/wslg/.X11-unix/X0 /tmp/.X11-unix/X0 [Install] WantedBy=multi-user.target
[Service] Type=oneshot ExecStart=-/usr/bin/umount /tmp/.X11-unix ExecStart=/usr/bin/rm -rf /tmp/.X11-unix ExecStart=/usr/bin/mkdir /tmp/.X11-unix ExecStart=/usr/bin/chmod 1777 /tmp/.X11-unix ExecStart=/usr/bin/ln -s /mnt/wslg/.X11-unix/X0 /tmp/.X11-unix/X0 ExecStart=/usr/bin/chmod 0777 /mnt/wslg/runtime-dir ExecStart=/usr/bin/chmod 0666 /mnt/wslg/runtime-dir/wayland-0.lock [Install] WantedBy=multi-user.target
-
Save the file and close the editor. Now we have to enable this service.
sudo systemctl enable wslg-fix.service
-
The last step is to configure the GNOME Shell to start in nested mode.
sudo mkdir /etc/systemd/user/gnome-shell-wayland.service.d/ sudo nano /etc/systemd/user/gnome-shell-wayland.service.d/override.conf
sudo mkdir /etc/systemd/user/org.gnome.Shell@wayland.service.d/ sudo nano /etc/systemd/user/org.gnome.Shell@wayland.service.d/override.conf
-
Paste the code below in the editor.
[Service] ExecStart= ExecStart=/usr/bin/gnome-shell --nested
-
Save the file and close the editor. Then close the distro terminal window.
-
Finally we will shutdown WSL.
wsl.exe --shutdown
The configuration is complete.
-
Now open again your distro terminal, then paste the command below.
DESKTOP_SESSION=ubuntu \ GDMSESSION=ubuntu \ GNOME_SHELL_SESSION_MODE=ubuntu \ GTK_IM_MODULE=ibus \ GTK_MODULES=gail:atk-bridge \ IM_CONFIG_CHECK_ENV=1 \ IM_CONFIG_PHASE=1 \ QT_ACCESSIBILITY=1 \ QT_IM_MODULE=ibus \ XDG_CURRENT_DESKTOP=ubuntu:GNOME \ XDG_DATA_DIRS=/usr/share/ubuntu:$XDG_DATA_DIRS \ XDG_SESSION_TYPE=wayland \ XMODIFIERS=@im=ibus \ MUTTER_DEBUG_DUMMY_MODE_SPECS=1366x768 \ gnome-session
-
A GNOME Shell window will appear.
Hi, @tamboril. Could you please tell me your distro and version, and show the output of the following command?