Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.

@sam0x17
Copy link

sam0x17 commented May 24, 2021

I had no problems with vscode + systemd + WSL + ubuntu 20.04 using ubuntu budgie as the desktop environment. I did sudo apt install ubuntu-budgie-desktop followed by these steps: https://gist.github.com/sam0x17/96341dc73e195c52d057f514d43d120f#file-wsl_install_internal-sh-L68-L88

@HuStmpHrrr
Copy link

HuStmpHrrr commented May 26, 2021

I followed these steps and it worked out with no pain: https://gist.github.com/SlvrEagle23/ce9e28adcec55504f3ed7d1fdc8ef573

@xpusostomos
Copy link

xpusostomos commented May 26, 2021

A tip for others, using rdp tends to work better than x servers. Especially multi-monitor (whether you want to devote all or only one monitor to it). install xrdp and /etc/init.d/xrdp start

@keli5
Copy link

keli5 commented Aug 3, 2021

It's very, very slow when doing this with Cinnamon. Does anyone know what drivers I would need for ubuntu 20.04?

@bossbeagle1509
Copy link

bossbeagle1509 commented Aug 3, 2021

If you're willing to sacrifice the desktop environment, then you can install an app called GWSL from the windows store. All apps instantly work out of the box as GUI's :)

@LuukvanKeeken
Copy link

LuukvanKeeken commented Sep 15, 2021

I have been using gnome for quite some time, but since updating to the latest version of Ubuntu (20.04.3 LTS) gnome-session is not working anymore (as in, it returns without actually starting up the desktop environment in VcXsrv). I've had this happen before, but usually restarting Windows would resolve the issue. gnome-session --debug returns the following output:

gnome-session-binary[463]: DEBUG(+): Enabling debugging
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:466): Gdk-ERROR **: 18:14:00.423: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: DEBUG(+): hardware acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: GLib-DEBUG(+): setenv()/putenv() are not thread-safe and should not be used after threads are created
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:469): Gdk-ERROR **: 18:14:00.608: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: WARNING: software acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: CRITICAL: We failed, but the fail whale is dead. Sorry....

This only happens when VcXsrv is also open. Has anyone else had similar issues? Would uninstalling and reinstalling gnome be an option?

@seba5496
Copy link

seba5496 commented Sep 16, 2021

How can I reverse the script, I think now it's interfering with my day-to-day work, and I cannot reset the entire distro. Any help?

@wxie2013
Copy link

wxie2013 commented Oct 13, 2021

gnome-session does not start in vcXsrc after I update the windows. Is does not produce any error message and just quit quiet. Any hints on how to diagnose it?

update: after running 'bash ubuntu-wsl2-systemd-script.sh --force', it works again

@asafhayoun
Copy link

asafhayoun commented Oct 25, 2021

I am getting an error saying Authorization required, but no authorization protocol specified image

I think you should Disable Access Control in your Xserver.

@marcussacana
Copy link

marcussacana commented Oct 25, 2021

what about this error?
image

@marcussacana
Copy link

marcussacana commented Oct 25, 2021

Okay, somehow fixed, I did this:

sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt-get upgrade

Now I created this file:
sudo nano /etc/X11/Xsession.d/98-gnome-session-disable-acceleration-check
and I put this script inside:

case "$STARTUP" in
     *gnome-session*)
       STARTUP="$STARTUP --disable-acceleration-check"
       ;;
     *x-session-manager*)
       if $(/usr/bin/update-alternatives --query x-session-manager|grep -q "^Value:.*gnome-session")
       then
         STARTUP="$STARTUP --disable-acceleration-check"
       fi
       ;;
esac

Now is ready, go to the windows CMD and wsl --shutdown...
Restart the wsl and run the session manager with this command: sudo su $USER -c 'gnome-session'

Not sure what happen here but gnome-session only just don't works.
image

@hbadi
Copy link

hbadi commented Nov 7, 2021

Hi,

Unfortuntly i ran your script under my wsl 2 ubuntu (which already works with graphics), but now nothing works...

@wxie2021
Copy link

wxie2021 commented Nov 13, 2021

Hi,

Unfortuntly i ran your script under my wsl 2 ubuntu (which already works with graphics), but now nothing works...

same problem here. The package works perfectly with VrxSrc but it breaks in the wslg. There are no error messages. when running gnome-tweaks, it shows the following error messages:

gnome-tweaks
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused

(gnome-tweaks:527): Gtk-WARNING **: 17:59:26.376: cannot open display: :0

@resonancedesigns
Copy link

resonancedesigns commented Nov 16, 2021

I can only get this to work as root or su with access control disabled in XServer. Is there a way to run it as a normal user? Pulse Audio among other things doesn't operate correctly or at all as root.

@marcussacana
Copy link

marcussacana commented Nov 16, 2021

I can only get this to work as root or su with access control disabled in XServer. Is there a way to run it as a normal user? Pulse Audio among other things doesn't operate correctly or at all as root.

sudo su $USER -c 'gnome-session'

@alibsg
Copy link

alibsg commented Nov 17, 2021

I have been using gnome for quite some time, but since updating to the latest version of Ubuntu (20.04.3 LTS) gnome-session is not working anymore (as in, it returns without actually starting up the desktop environment in VcXsrv). I've had this happen before, but usually restarting Windows would resolve the issue. gnome-session --debug returns the following output:

gnome-session-binary[463]: DEBUG(+): Enabling debugging
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:466): Gdk-ERROR **: 18:14:00.423: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: DEBUG(+): hardware acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: GLib-DEBUG(+): setenv()/putenv() are not thread-safe and should not be used after threads are created
gnome-session-binary[463]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)

(gnome-session-check-accelerated:469): Gdk-ERROR **: 18:14:00.608: The program 'gnome-session-check-accelerated' received an X Window System error.
This probably reflects a bug in the program.
The error was 'GLXBadFBConfig'.
  (Details: serial 187 error_code 163 request_code 149 (GLX) minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
gnome-session-binary[463]: WARNING: software acceleration check failed: Child process killed by signal 5
gnome-session-binary[463]: CRITICAL: We failed, but the fail whale is dead. Sorry....

This only happens when VcXsrv is also open. Has anyone else had similar issues? Would uninstalling and reinstalling gnome be an option?

I had the same issue on running gnome-session and I realized that it is due to checking hardware acceleration by gnome-session.
run with: =>>>> gnome-session --disable-acceleration-check
It works fine for me now.
This may be a solution for others which have the problem that the installation and run every thing is ok but there is only black screen.

@kid1412621
Copy link

kid1412621 commented Nov 26, 2021

what's the difference between sudo apt install ubuntu-desktop gnome and sudo apt install ubuntu-gnome-desktop?

@kid1412621
Copy link

kid1412621 commented Nov 26, 2021

gnome-session --disable-acceleration-check

new error showed up:

$  gnome-session --disable-acceleration-check
gnome-session-binary[361]: WARNING: Using null backend for session tracking
_IceTransmkdir: ERROR: euid != 0,directory /tmp/.ICE-unix will not be created.
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
SSH_AUTH_SOCK=/home/kid/.cache/keyring-SSTID1/ssh
GNOME_KEYRING_CONTROL=/home/kid/.cache/keyring-SSTID1
SSH_AUTH_SOCK=/home/kid/.cache/keyring-SSTID1/ssh
Window manager warning: Unsupported session type
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Window manager warning: Unsupported session type
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
gnome-session-binary[361]: WARNING: App 'org.gnome.Shell.desktop' respawning too quickly
gnome-session-binary[361]: CRITICAL: We failed, but the fail whale is dead. Sorry....

@foghina
Copy link

foghina commented Dec 9, 2021

OK finally got it working, figured I'd share my struggles.

  1. Turned out I only allowed VcXsrv on private networks. I was stuck on this for a good while. Don't be an idiot like me. When I went into firewall settings though, for some reason the app was registered twice? I removed both and re-launched, making sure to tick both boxes.
  2. I was adding the -ac parameter wrong. When you type the path in, Windows Terminal autocompletes to something like:
PS C:\Users\felix> & 'C:\Program Files\VcXsrv\vcxsrv.exe'

Tried adding -ac to the end of that (both within and outside the single quotes) but I don't think it gets picked up. I ended up just doing:

PS C:\Users\felix> cd 'C:\Program Files\VcXsrv\'
PS C:\Program Files\VcXsrv> .\vcxsrv.exe -ac

FWIW, if you're seeing the "respawning too quickly" warning, this was the fix for me.

3... I also ran into the acceleration check issue. Simply disabling it didn't work at first (gnome showed up but was unresponsive). Using sudo su $USER -c 'gnome-session' fixed it, so I suspect some sort of permissions/environment issue. However now it looks like disabling the check also works so I'm no sure what changed (perhaps it was (2)).

@MarceloMachadoxD
Copy link

MarceloMachadoxD commented Mar 10, 2022

OK finally got it working, figured I'd share my struggles.

  1. Turned out I only allowed VcXsrv on private networks. I was stuck on this for a good while. Don't be an idiot like me. When I went into firewall settings though, for some reason the app was registered twice? I removed both and re-launched, making sure to tick both boxes.
  2. I was adding the -ac parameter wrong. When you type the path in, Windows Terminal autocompletes to something like:
PS C:\Users\felix> & 'C:\Program Files\VcXsrv\vcxsrv.exe'

Tried adding -ac to the end of that (both within and outside the single quotes) but I don't think it gets picked up. I ended up just doing:

PS C:\Users\felix> cd 'C:\Program Files\VcXsrv\'
PS C:\Program Files\VcXsrv> .\vcxsrv.exe -ac

FWIW, if you're seeing the "respawning too quickly" warning, this was the fix for me.

3... I also ran into the acceleration check issue. Simply disabling it didn't work at first (gnome showed up but was unresponsive). Using sudo su $USER -c 'gnome-session' fixed it, so I suspect some sort of permissions/environment issue. However now it looks like disabling the check also works so I'm no sure what changed (perhaps it was (2)).

thanks guy it worked here still seems broken but works

Copy link

ghost commented Apr 2, 2022

Systemd bootloop?
изображение

@efhayes2
Copy link

efhayes2 commented Apr 27, 2022

Nice! 2022, and that still seems to work.

I say "seems", because I may be hung on the "Welcome!" screen, but that's more than I had before

@irfancode
Copy link

irfancode commented May 16, 2022

So far full desktop experience WSL2
https://www.kali.org/docs/wsl/win-kex/

@Wither-Skeleton
Copy link

Wither-Skeleton commented Jun 19, 2022

what's this error?
image

@foxtr0
Copy link

foxtr0 commented Jul 5, 2022

It's very, very slow when doing this with Cinnamon. Does anyone know what drivers I would need for ubuntu 20.04?

Did you find a solution? Its really slow for me too.

@rjolbrich
Copy link

rjolbrich commented Jul 7, 2022

Hello,
I think I'm dabbling in something over my head, but....

Has anyone persued this with Ubuntu and Distrod to provide systemd?

I have seen discussions about genie, but have attempted to use Distrod as a first step.

I am using VcXsrv also.

After successfully installing Distrod and starting VcXsrv, an attempt to start gnome-session yields the following Debug:

rjolbrich@DESKTOP-6OBTGF6:~$ sudo gnome-session --debug
gnome-session-binary[957]: DEBUG(+): Enabling debugging
gnome-session-binary[957]: GLib-DEBUG(+): posix_spawn avoided (fd close requested)
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of QT_IM_MODULE=ibus environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of XMODIFIERS=@im=ibus environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of GNOME_DESKTOP_SESSION_ID=this-is-deprecated environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of XDG_MENU_PREFIX=gnome- environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): Finding a graphical session for user 0
gnome-session-binary[957]: WARNING: Could not get session id for session. Check that logind is properly installed and pam_systemd is getting used at login.
gnome-session-binary[957]: DEBUG(+): Using systemd for session tracking
gnome-session-binary[957]: GLib-GIO-DEBUG(+): _g_io_module_get_default: Found default implementation dconf (DConfSettingsBackend) for ‘gsettings-backend’
gnome-session-binary[957]: DEBUG(+): GsmManager: setting client store 0x7ff5e800f420
gnome-session-binary[957]: DEBUG(+): Could not make systemd aware of SESSION_MANAGER=local/DESKTOP-6OBTGF6:@/tmp/.ICE-unix/957,unix/DESKTOP-6OBTGF6:/tmp/.ICE-unix/957 environment variable: GDBus.Error:org.freedesktop.DBus.Error.Spawn.ChildExited: Process org.freedesktop.systemd1 exited with status 1
gnome-session-binary[957]: DEBUG(+): GsmXsmpServer: SESSION_MANAGER=local/DESKTOP-6OBTGF6:@/tmp/.ICE-unix/957,unix/DESKTOP-6OBTGF6:/tmp/.ICE-unix/957

gnome-session-binary[957]: DEBUG(+): emitting SessionIsActive
gnome-session-binary[957]: DEBUG(+): fill: *** Getting session 'gnome'
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /root/.config/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/root/.config/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /etc/xdg/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/etc/xdg/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /usr/local/share/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/usr/local/share/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: DEBUG(+): fill: *** Looking if /usr/share/gnome-session/sessions/gnome.session is a valid session file
gnome-session-binary[957]: DEBUG(+): Cannot use session '/usr/share/gnome-session/sessions/gnome.session': non-existing or invalid file.
gnome-session-binary[957]: CRITICAL: We failed, but the fail whale is dead. Sorry....
rjolbrich@DESKTOP-6OBTGF6:~$

Like I said I may be over my head. Is this a Distrod/systemd problem or a VcXsrv problem?

@mingsxs
Copy link

mingsxs commented Jul 7, 2022

I don't really recommend adopting this method to set up the gnome desktop for your WSL2 if your windows is not new enough to get the builtin WSL2 GNOME desktop support. I tried this way yesterday and it ruined my network setting since the systemd daemon will initialize some socks and occupy some ports, then somehow both my neovim and ms store in windows were broken. :(
It took me nearly a whole afternoon to narrow down this issue, cause I didn't realize it could have anything to do this system hack at all. However, after removing this systemd hack stuff, my neovim and MS store came back right away.

@mingsxs
Copy link

mingsxs commented Jul 7, 2022

Guys who think this workaround is appealing should be noted.

@andmpel
Copy link

andmpel commented Jul 11, 2022

@mingsxs, which version if any does support gnome desktop?

@linuxnoob121
Copy link

linuxnoob121 commented Jul 12, 2022

Hi there, I used the script today and would now like to undo the changes, is there any way to do this? I had xrdp installed with xfce4 and it no longer works after I used this script. I renamed the start-systemd-namespace script thing in /usr/sbin/ as a temporary fix, but xrdp still is not working with xfce4. Help would be greatly appreciated.

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