Ubuntu 24.04 background

Gnome Desktop on WSL-2 Using Ubuntu

Avi Varma
3 min readMay 24, 2024

In my previous tutorial I showed how to setup Debain on WSL-2 with SystemD enabled. Now let’s take this one step further and install GNOME desktop and use our WSL2 VMs with a full GUI!

  • Start off by installing Ubuntu on WSL2 using the following command: wsl --install -d ubuntu
  • Once you have Ubuntu set up, run the following commands:
sudo apt update
sudo apt-mark hold acpid acpi-support
sudo apt upgrade
  • Now we can run a helpful systemd setup script which sets up a systemd environment within WSL by installing necessary packages, copying scripts, configuring sudoers, modifying bash.bashrc, and setting environment variables in Windows. It allows users to use systemd within WSL, enabling services and other features typically unavailable in WSL's default init system.
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
./ubuntu-wsl2-systemd-script.sh
  • Now exit WSL and in a powershell or cmd terminal run the following commands to restart and update WSL:
wsl.exe -d ubuntu --shutdown
wsl.exe -d ubuntu
  • When you are back in the Ubuntu command line in WSL, export the following environment variables:
export DISPLAY="$(ip route | awk '{print $3; exit}')":0;
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
export XDG_SESSION_DESKTOP=ubuntu
export XDG_SESSION_TYPE=x11
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_SESSION_CLASS=user
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_RUNTIME_DIR="/run/user/1000"
  • Now run the following commands:
sudo mkdir -p /run/user/1000
sudo chmod 700 /run/user/1000
sudo chown $(whoami): /run/user/1000
  • That’s all the setup done, so lets now install gnome desktop:
sudo apt install ubuntu-desktop gnome
  1. Go to https://sourceforge.net/projects/vcxsrv/ to download VcXsrv Windows X Server. The version I am using is 1.20.14.0. Install it in Windows.
  2. Start VcXsrv by running XLaunch in Windows (if a previous VcXsrv is running, exit it. The settings of VcXsrv matter). Select “Fullscreen” in the first page. Fill up the “Additional parameters for VcXsrv” field in the third page with -ac -wgl -dpms.

When VcXsrv starts, you might see a whole black screen. That’s the effect of full screen without contents yet. Press Alt-Tab to switch to Ubuntu command line in WSL.

  1. Run dbus-launch --exit-with-session gnome-session
  2. Go to the full-screen VcXsrv window. The Ubuntu GNOME desktop should show up now. Enjoy!
  3. You can just leave the GNOME alone when you don’t use it. But if you really wanna quit GNOME, either close the VcXsrv window or press Ctrl-C on the Ubuntu command line in WSL.

Note this is a bit slow in performance, I’m not sure how to enable GPU acceleration right now but this is a start!

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Avi Varma
Avi Varma

Written by Avi Varma

Hi! I’m a Computer Science graduate in a software product company.

Responses (6)

Write a response

I followed these steps but I"m getting an error when I try to run gnome typing "dbus-launch --exit-with-session gnome-session".
The error I get is:
gnome-session-binary[24513]: WARNING: Failed to upload environment to systemd…

this is great, I've been trying to do this for a long time without good results, and this guide worked perfectly. thanks!

I am getting the following error :
"
Oh no! something has gone wrong
a problem has occured and the system cant recover . all extensions have been disabled as a precaution"