Jump to content
Search

This wiki is under development. Features may be missing. Data loss is unlikely, but possible. Read the announcement.

Install an Ubuntu Desktop environment on WSL

From Ubuntu Wiki
Info
This guide was adapted from a GitHub Gist by user b23prodtm: Set up a GNOME desktop environment on WSL 2.

Running a desktop environment from WSL is an unusual use-case that is not officially supported.

Requirements

  • WSL 2
  • At least Ubuntu 24.04
  • An X server for Windows, such as VcXsrv
  • Basic knowledge of how to run GUI apps with WSL 2

Update packages

Ensure your packages are up to date:

sudo apt update
sudo apt upgrade

Install GNOME

Run the following command:

sudo apt install ubuntu-desktop gnome

Edit bashrc

Open up your ~/.bashrc:

nano ~/.bashrc

Append these lines and save the file:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
export LIBGL_ALWAYS_INDIRECT=1

(optional) Troubleshooting systemd

If you try to start GNOME now, you may get a lot of errors:

Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6054): Gtk-WARNING **: 11:04:51.973: cannot open display: :0
Unable to init server: Could not connect: Connection refused

(gnome-session-check-accelerated:6055): Gtk-WARNING **: 11:04:52.234: cannot open display: :0
gnome-session-binary[6044]: WARNING: software acceleration check failed: Child process exited with code 1
gnome-session-binary[6044]: CRITICAL: We failed, but the fail whale is dead. Sorry....

If you do, you should check that systemd is enabled in your WSL instance. The following lines should appear in wsl.conf:

[boot]
systemd=true

Shutdown WSL

Run the following in PowerShell:

wsl --shutdown

Starting GNOME

First, start your X server on Windows. Make sure you let it through your firewall and disable access control.

Then launch Ubuntu on WSL again and start GNOME:

gnome-session

If you don't get any error messages, you should be good. Wait a few seconds for GNOME to start up.

Notes

  • You can disable the screensaver with gsettings set org.gnome.desktop.session idle-delay 0.
  • You can also list the currently running instances with:
    wsl --list --verbose