Skip to content

Instantly share code, notes, and snippets.

@Ta180m
Last active April 27, 2024 10:35
Show Gist options
  • Save Ta180m/e1471413f62e3ed94e72001d42e77e22 to your computer and use it in GitHub Desktop.
Save Ta180m/e1471413f62e3ed94e72001d42e77e22 to your computer and use it in GitHub Desktop.
Set up a GNOME desktop environment on WSL 2

WSL 2 GNOME Desktop

NOTE: If you want the ultimate Linux desktop experience, I highly recommend installing Linux as your main OS. I no longer use Windows (except in a VM) so I will not be maintaining this guide anymore.

Think Xfce looks dated? Want a conventional Ubuntu experience? This tutorial will guide you through installing Ubuntu's default desktop environment, GNOME.

GNOME is one of the more complex — and that means more difficult to run — desktop environments, so for years people couldn't figure out how to run it on WSL 2. On WSL 1 it could only run using very complicated methods that didn't transfer to well WSL 2. Any forlorn attempts to run it on WSL 2 only resulted in a smoldering heap of error messages.

But now you can!

Requirements:

  • WSL 2
  • Ubuntu 20.04 (other distros not tested)
  • An X server for Windows, such as VcXsrv
  • Basic knowledege on how to run GUI apps with WSL 2 (not required but highly recommended)

Getting ready

You've been regularly updating your distro, haven't you?

sudo apt update
sudo apt upgrade

Install GNOME: (maybe go eat a snack while it's installing?)

sudo apt install ubuntu-desktop gnome

Open up your ~/.bashrc:

nano ~/.bashrc

And paste this in at the end and save:

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

If you try to start GNOME now, you'll get a lot of errors. Something along the lines of this, but a ton more 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....

The trick is to enable systemd: (note that this does break a lot of stuff such as Visual Studio Code Remote)

git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh

Now shut down WSL 2: (run this in Windows)

wsl --shutdown

Starting GNOME

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

Now, start up Ubuntu 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.

desktop

Now you have a great GUI desktop and you won't need any intensive virtual machines anymore!

Profit?

Notes

  • You can disable the screensaver with gsettings set org.gnome.desktop.session idle-delay 0.
  • You can also try KDE Plamsa using a similar method! Just sudo apt install kde-plasma-desktop instead and start it with startplasma-x11.

Troubleshooting

If you can't get this to work, try Xfce.

If you still can't get it to work, you can ask for help on an online forum such as r/bashonubuntuonwindows.

@yukilikespie
Copy link

@kothapet I also had the same issue, but then I set guiApplications to false, like here: https://github.com/microsoft/wslg#wslg-system-distro and it worked afterwards.

@kartik-47
Copy link

I have the same issue as ghost - this has put my system into an infinite look that just keeps saying "sleeping for one second to let systems settle".
I'm going to have to reinstall Ubuntu.

Maybe you can access the hard disk of the wsl2 vm from windows, I think it’s a vhd you could mount, located somewhere in c:/users/Appdata. Then look in /etc/bash.bashrc for the line source /usr/sbin/start-systemd-namespace and delete it. or delete /usr/sbin/start-systemd-namespace altogether

But I am not able to edit this bashrc file, can you please help me with this?

@ranasaria
Copy link

I get this error when I try to start ubuntu having shut it down:

Cannot execute daemonize to start systemd.

[process exited with code 1 (0x00000001)]
You can now close this terminal with Ctrl+D, or press Enter to restart.

@rock3tsprocket
Copy link

rock3tsprocket commented Jan 31, 2024

?
bskdjghsdjgkgkgrlekgekjgldgbkdnglgbdkfngkjbglefgkbfjngerkgbelgbkfejbglfdbg
Yes, i done all the previous steps except for bashing the sh file (which i done just now), but when running Gnome this happens.
Edit: after rebooting Ubuntu 22.04 it doesn't even work anymore

@Momo140868
Copy link

You saved my life with all this, thank you very much

@lorksoft
Copy link

lorksoft commented Feb 14, 2024

anyone get this working with regular windows 11 wslg and native systemd? I might take a swing at it

Yes,after the step, in the first post (git clone ......) (i try it on debian)

i don't use vxsrv
i install Xephyr

sudo apt install xserver-xephyr

and

Xephyr :2 &
DISPLAY=:2
gnome-session

play with Xephyr options to change size ...

@ARntn
Copy link

ARntn commented Feb 25, 2024

can you use it with debian wsl too?

@lorksoft
Copy link

Yes, i do it on Debian

@lanietoc
Copy link

it is recommended to install gWSL from the store. gWSL works out of the box. there is no need to configure your own x client now.

Looks great but it's not free.
Thanks for your recommendation.

@andmpel
Copy link

andmpel commented Apr 3, 2024

anyone get this working with regular windows 11 wslg and native systemd? I might take a swing at it

Yes,after the step, in the first post (git clone ......) (i try it on debian)

i don't use vxsrv i install Xephyr

sudo apt install xserver-xephyr

and

Xephyr :2 &
DISPLAY=:2
gnome-session

play with Xephyr options to change size ...

Thanks this worked for me I tried on Windows 11 with Debian as you suggested.

Notes:

  • You do still need to clone and install script from the repo
  • You need to type enter "export DISPLAY=:2"

@Guarmanda
Copy link

Guarmanda commented Apr 4, 2024

The first times I tried, I got the "oh no" screen like gnome crashed, but still gave me the option to chose a keyboard.
I restarted wsl, and now it won't show me any window, and gnome-shell no longer generate logs, I just have the command indefinitelly loading or something...
image
adding the .wlsconfig didn't solve the issue for me

Restarting wsl deletes the /run/user/1000 folder, and changes the /etc/resolv.conf, cutting internet connection at startup, because default dns doesn't work. It may have other bad effects on system files, don't know which ones.

Running gnome-session doesn't generate any logs. Gnome-shell did generate some logs the first times I launched it, before restarting.

Reinstalling ubuntu didn't re-gave me the "oh no" screen, I fall directly into the not-any-error and not-any-log state

@GF1314
Copy link

GF1314 commented Apr 25, 2024

当我启动 gnome-session 时,我明白了。我尝试了此线程中的所有选项,但总是收到此错误。 图像我可以启动任何 X 应用程序、firefox、gnome-term 等,但由于某种原因会话不想启动,并且 --debug 确实显示任何错误,只是一些警告。

gnome-session-binary[88121]: 调试(+): GsmManager: 将客户端添加到结束会话客户端: /org/gnome/SessionManager/Client4 gnome-session-binary[88121]: 调试(+): GsmManager: 将客户端添加到结束会话客户端: /org/gnome/SessionManager/Client13 gnome-session-binary[88121]: 调试(+): GsmManager: 将客户端添加到结束会话客户端: /org/gnome/SessionManager/Client7gnome-session-binary[88121]: 调试(+): GsmManager: 将客户端添加到结束会话客户端: /org/gnome/SessionManager/Client16 gnome-session-binary[88121]: 调试(+): GsmDBusClient: 得到 EndSessionResponse is-ok:1 reason= gnome-session-binary[88121]: DEBUG(+): GsmManager: end session request 的响应: is-ok=1 do-last=0 cancel=0 reason= gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=gnome-session-binary[88121]: 调试(+): GsmManager: 来自结束会话请求的响应: is-ok=1 do-last=0 cancel=0 reason= gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason= gnome-session-binary[88121]: DEBUG(+): GsmManager: 来自结束会话请求的响应: is-ok=1 do-last=0 cancel=0 reason= gnome-session-binary[88121]: DEBUG(+): GsmDBusClient: got EndSessionResponse is-ok:1 reason=

有些东西正在生成结束会话,我不知道是什么。

Have you solved this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment