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.

@AnishDe12020

This comment has been minimized.

Copy link

@AnishDe12020 AnishDe12020 commented Nov 11, 2020

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

@Ta180m

This comment has been minimized.

Copy link
Owner Author

@Ta180m Ta180m commented Nov 11, 2020

@longtnhe140627

This comment has been minimized.

Copy link

@longtnhe140627 longtnhe140627 commented Nov 11, 2020

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

type: sudo su
then enter your password then run gnome-session

@ErnieBernie10

This comment has been minimized.

Copy link

@ErnieBernie10 ErnieBernie10 commented Nov 12, 2020

I am able to run gnome-session without errors, but nothing shows up on my xserver.

@AnishDe12020

This comment has been minimized.

Copy link

@AnishDe12020 AnishDe12020 commented Nov 12, 2020

I got it to work through RDP (Remote Desktop Protocol)

@ErnieBernie10

This comment has been minimized.

Copy link

@ErnieBernie10 ErnieBernie10 commented Nov 18, 2020

I am able to run gnome-session without errors, but nothing shows up on my xserver.

Anyone with this issue. Try running VcXsrv with -ac command arguments. That worked for me.

@mikebiondi

This comment has been minimized.

Copy link

@mikebiondi mikebiondi commented Nov 23, 2020

I was so excited to try this, I didn't check to see I was really on wsl2. It turns out I'm using WSL1. There's no easy way to back this out without digging through the script. Why update /etc/bash.bashrc instead of just the local .bashrc? Doing it on a local .bashrc means I can create another account and play around with it before commiting.

@0Vipin0

This comment has been minimized.

Copy link

@0Vipin0 0Vipin0 commented Nov 28, 2020

Can't get it working. Installation was successfully completed but when I ran the script, it throws me this error.

hwclock: Cannot access the Hardware Clock via any known method.

This error pops up.

@ArmandXiao

This comment has been minimized.

Copy link

@ArmandXiao ArmandXiao commented Jan 1, 2021

Fantastic!

  • Ubuntu 20.04 works perfectly fine with WSL2

Reminder:

  • I tried with 18.04 and nothing, no error yet nothing shown

Thank u!! :)

@ArmandXiao

This comment has been minimized.

Copy link

@ArmandXiao ArmandXiao commented Jan 1, 2021

I am able to run gnome-session without errors, but nothing shows up on my xserver.

Are u Using Ubuntu20.04 LTS? Which version are u using?

  • My 18.04 LTS fails but 20.04 LTS works
@greerda

This comment has been minimized.

Copy link

@greerda greerda commented Jan 2, 2021

I followed direction and didn't work for me -- I get nothing. Maybe a youtube video?

@NarutoUA

This comment has been minimized.

Copy link

@NarutoUA NarutoUA commented Jan 2, 2021

I followed direction and didn't work for me -- I get nothing. Maybe a youtube video?

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

@danielkrajnik

This comment has been minimized.

Copy link

@danielkrajnik danielkrajnik commented Jan 4, 2021

Tried it on Ubuntu 18.04 and after restarting windows wsl2 exits immediately after launching it:

nsenter: failed to parse pid: '191
192'

EDIT: it's working again. I restarted it again a couple of times, restarted Lxss service, but not sure what exactly repaired it...

@MeowcaTheoRange

This comment has been minimized.

Copy link

@MeowcaTheoRange MeowcaTheoRange commented Jan 24, 2021

I keep getting Sleeping for 1 second to let systemd settle.

Try uninstalling your ubuntu application via Settings and reinstalling via Windows Store

@slashtechno

This comment has been minimized.

Copy link

@slashtechno slashtechno commented Jan 27, 2021

How do you set up the X server?

@slashtechno

This comment has been minimized.

Copy link

@slashtechno slashtechno commented Jan 28, 2021

Sorry I keep commenting, I still get Sleeping for 1 second to let systemd settle

@marksustin

This comment has been minimized.

Copy link

@marksustin marksustin commented Jan 28, 2021

Sorry I keep commenting, I still get Sleeping for 1 second to let systemd settle

@MeowcaTheoRange already replied you. Did you try following the steps?

@slashtechno

This comment has been minimized.

Copy link

@slashtechno slashtechno commented Jan 28, 2021

I reset the application through settings (cleared all app data) and did all the steps again.

Do I need to uninstall?

@marksustin

This comment has been minimized.

Copy link

@marksustin marksustin commented Jan 29, 2021

I reset the application through settings (cleared all app data) and did all the steps again.

Do I need to uninstall?

Not sure it'll help, but I think you should try

@marksustin

This comment has been minimized.

Copy link

@marksustin marksustin commented Jan 29, 2021

How do you set up the X server?

Do you know the answer now?

@slashtechno

This comment has been minimized.

Copy link

@slashtechno slashtechno commented Jan 29, 2021

How do you set up the X server?

Do you know the answer now?

Yes

@beanorx

This comment has been minimized.

Copy link

@beanorx beanorx commented Feb 2, 2021

https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git is gone. so theres no script for that step.

@elias-rincon

This comment has been minimized.

Copy link

@elias-rincon elias-rincon commented Feb 7, 2021

https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git is gone. so theres no script for that step.

It's online again

@AFalseHuman

This comment has been minimized.

Copy link

@AFalseHuman AFalseHuman commented Feb 7, 2021

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....

This Error Keeps Showing When I DO gnome-session

I followed the systemd trick but still not working .

@nazaruuyee

This comment has been minimized.

Copy link

@nazaruuyee nazaruuyee commented Feb 20, 2021

Try worked systemd enabler here :
https://github.com/arkane-systems/genie

don't forget to add microsoft package repository first when install dotnet-runtime-5.0
when done, just type wsl genie -s in cmd.
If waiting systemd...!!!! too long, just open the distro and type again genie -s (make sure hostname in distro added with (hostname)-wsl). Then just type "ps -ef", when you see systemd in PID 1, you're good to go.

@johentsch

This comment has been minimized.

Copy link

@johentsch johentsch commented Feb 21, 2021

I am able to run gnome-session without errors, but nothing shows up on my xserver.

Anyone with this issue. Try running VcXsrv with -ac command arguments. That worked for me.

Got the same problem: Type gnome-session and nothing happens. Tried your fix by running "C:\Program Files\VcXsrv\xlaunch.exe" -ac, is that what you meant? Didn't change anything :-( Trying this with Ubuntu 20.04.2 LTS running 5.4.72-microsoft-standard-WSL2 kernel.

@jrunestone

This comment has been minimized.

Copy link

@jrunestone jrunestone commented Mar 12, 2021

I was hoping for this one, alas, also just getting a black screen with or without different arguments and settings. No errors from gnome-session.
EDIT: Got it working! I had to disable the Windows firewall for the "Public" network.

@slashtechno

This comment has been minimized.

Copy link

@slashtechno slashtechno commented Mar 12, 2021

Could this please be turned into an automated script? Even better, can this be tuned into a repository.

@somyaSarathi

This comment has been minimized.

Copy link

@somyaSarathi somyaSarathi commented Mar 13, 2021

I'm getting this error. What should I do?
Capture

@diramazioni

This comment has been minimized.

Copy link

@diramazioni diramazioni commented Mar 15, 2021

EDIT: Got it working! I had to disable the Windows firewall for the "Public" network.
@jrunestone me too!!!! you knoiw a better way without having to disable the entire firewall?

nvm on windows firewall you can make an exception ticking the public network for vcxsrv

@ThatsNiceGuy

This comment has been minimized.

Copy link

@ThatsNiceGuy ThatsNiceGuy commented Mar 22, 2021

works for me but is it possible for audio to be supported?

@nikospamp

This comment has been minimized.

Copy link

@nikospamp nikospamp commented Mar 27, 2021

@kerningium Did you manage to find a solution? I am facing the same problem

{19:01}/mnt/c/Users/User ➭ gnome-session
gnome-session-binary[29]: WARNING: Using null backend for session tracking
GNOME_KEYRING_CONTROL=/home/pampoukidis/.cache/keyring-R96H00
GNOME_KEYRING_CONTROL=/home/pampoukidis/.cache/keyring-R96H00
SSH_AUTH_SOCK=/home/pampoukidis/.cache/keyring-R96H00/ssh
GNOME_KEYRING_CONTROL=/home/pampoukidis/.cache/keyring-R96H00
SSH_AUTH_SOCK=/home/pampoukidis/.cache/keyring-R96H00/ssh
Window manager warning: Unsupported session type
gnome-session-binary[29]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Window manager warning: Unsupported session type
gnome-session-binary[29]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
gnome-session-binary[29]: WARNING: App 'org.gnome.Shell.desktop' respawning too quickly
gnome-session-binary[29]: CRITICAL: We failed, but the fail whale is dead. Sorry....

Edit

Deleting ubuntu from PC and re-installing them solved this error.

Edit 2

Don't forget to use -ac as argument. Vcxsrv -ac

https://www.reddit.com/r/bashonubuntuonwindows/comments/hl0idv/wsl2_ubuntu_gnome_xrdp/fww650m/?utm_source=reddit&utm_medium=web2x&context=3

@bossbeagle1509

This comment has been minimized.

Copy link

@bossbeagle1509 bossbeagle1509 commented Mar 30, 2021

Everything works fine, except that fairly often, the x server window freezes and I have to close it and run gnome-session and VcXsrv again, Any ideas as to why ?

@fengmao31

This comment has been minimized.

Copy link

@fengmao31 fengmao31 commented Mar 30, 2021

microsoft/WSL#4106
Xserver -ac and firwall

@Ekaitxue

This comment has been minimized.

Copy link

@Ekaitxue Ekaitxue commented Apr 1, 2021

Everything works, no errors at all... But no gnome in any xming window pops up. Absolutely nothign happens
image

@Ekaitxue

This comment has been minimized.

Copy link

@Ekaitxue Ekaitxue commented Apr 1, 2021

with some tweaks everything worked wonderfully just start your xserver with -ac (btw i switched from xming to vcxsrv)

@S4my4k

This comment has been minimized.

Copy link

@S4my4k S4my4k commented Apr 3, 2021

@bossbeagle1509

This comment has been minimized.

Copy link

@bossbeagle1509 bossbeagle1509 commented Apr 3, 2021

https://gist.github.com/Ta180m/e1471413f62e3ed94e72001d42e77e22#notes
So can I use the Internet or not?

I was able to use the internet smoothly after I installed firefox with sudo apt install firefox.

@muhammadadnanzaib

This comment has been minimized.

Copy link

@muhammadadnanzaib muhammadadnanzaib commented Apr 8, 2021

awesom tutorial, very easy to follow. Got it running in the first go,

@engnilsonsp

This comment has been minimized.

Copy link

@engnilsonsp engnilsonsp commented Apr 8, 2021

When I start Ubuntu, the window closes... And by the "Windows Terminal", this message appears:
Cannot execute daemonize to start systemd.
[processo encerrado com o código 1]

And stops the prompt... Can you help?

@bossbeagle1509

This comment has been minimized.

Copy link

@bossbeagle1509 bossbeagle1509 commented Apr 8, 2021

When I start Ubuntu, the window closes... And by the "Windows Terminal", this message appears:
Cannot execute daemonize to start systemd.
[processo encerrado com o código 1]

And stops the prompt... Can you help?

Try sudo apt-get install -y daemonize

@muhammadadnanzaib

This comment has been minimized.

Copy link

@muhammadadnanzaib muhammadadnanzaib commented Apr 8, 2021

your issue is already asked by someone else:
DamionGans/ubuntu-wsl2-systemd-script#37

The solution is also already posted:
DamionGans/ubuntu-wsl2-systemd-script#44

I hope this helps.

@engnilsonsp

This comment has been minimized.

Copy link

@engnilsonsp engnilsonsp commented Apr 8, 2021

Well, I find some possible help:

Looks like daemonize wasn't found for some reason.

You should be able to log into WSL by typing "wsl -u root" in cmd or powershell.
Check if daemonize is installed by typing "which daemonize".
I assume you'll have no output (I have "/usr/bin/daemonize" for example).
If you do have some output, please post it in a reply.
You can either install daemonize or disable the startup script.

To install daemonize type:
"sudo apt-get install daemonize"
Do note however, that it's quite likely that the other things the script tried to install failed.
You can run the script again in that case. Remember to sudo it.

If you want to disable the systemd start script, do the following:
Enter in "nano /etc/bash.bashrc"
Put a # on the start of the line that says "source /usr/sbin/start-systemd-namespace"
To enable the systemd start script again, simply remove the newly added #
...........
By Xideta, commented on 10 Aug 2020 --> DamionGans/ubuntu-wsl2-systemd-script#37

Thanks...

@wgtLencha

This comment has been minimized.

Copy link

@wgtLencha wgtLencha commented Apr 25, 2021

You are amazing. After so many painful tries, I succeeded. I have a great WSL2 ubuntu gnome desktop experience.

@sam0x17

This comment has been minimized.

Copy link

@sam0x17 sam0x17 commented Apr 28, 2021

any way to set this up without breaking VS code connecting to WSL?

@kevinmmansour

This comment has been minimized.

Copy link

@kevinmmansour kevinmmansour commented May 18, 2021

any way to set this up without breaking VS code connecting to WSL?

I recommend to wait sometimes. Microsoft will support Linux GUI Apps Officially which will be faster and better and won't break VS Code connecting to WSL. Also Linux GUI Apps is only for Windows Insider (Dev Channel) but very soon it will come to normal users and it will be great experiences. :)

@xpusostomos

This comment has been minimized.

Copy link

@xpusostomos xpusostomos commented May 22, 2021

OK, so Microsoft has announced and released in beta, gui apps for wsl. But will this allow us to run Gnome? From what I can tell, not really. Anybody have any insight?

@sam0x17

This comment has been minimized.

Copy link

@sam0x17 sam0x17 commented May 22, 2021

update: vscode doesn't break at all

@kevinmmansour

This comment has been minimized.

Copy link

@kevinmmansour kevinmmansour commented May 22, 2021

OK, so Microsoft has announced and released in beta, gui apps for wsl. But will this allow us to run Gnome? From what I can tell, not really. Anybody have any insight?

It won't run Gnome. Only GUI apps for now, but that might change in Future. :)

@kevinmmansour

This comment has been minimized.

Copy link

@kevinmmansour kevinmmansour commented May 22, 2021

update: vscode doesn't break at all

Maybe you are right, but systemd might break it.

@bossbeagle1509

This comment has been minimized.

Copy link

@bossbeagle1509 bossbeagle1509 commented May 22, 2021

Maybe you are right, but systemd might break it.

I tried installing systemd to use snap. It promptly broke something that x server was using and I wasn't able to get a session at all, which sort of defeated the purpose.

@kevinmmansour

This comment has been minimized.

Copy link

@kevinmmansour kevinmmansour commented May 22, 2021

Maybe you are right, but systemd might break it.

I tried installing systemd to use snap. It promptly broke something that x server was using and I wasn't able to get a session at all, which sort of defeated the purpose.

I do not recommend to install systemd. Microsoft is working on Official systemd for WSL whcih it will be more than perfect but wait a while untill Microsoft release it. Also you might use systemd until Microsft Support it officially. And actually yes. X server might get broke due to systemd; You will se shortcuts not working and apps might not launch. :)

@xpusostomos

This comment has been minimized.

Copy link

@xpusostomos xpusostomos commented May 22, 2021

Does the Microsoft GUI announcement buy us anything as far as wanting to run Gnome? For example, it apparently automatically starts up a Wayland server when you start a gui app. Can that part at least be leveraged to run Gnome? I'm curious what happens when you launch gnome-session when this Microsoft gui stuff is active.

@sam0x17

This comment has been minimized.

Copy link

@sam0x17 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

This comment has been minimized.

Copy link

@HuStmpHrrr HuStmpHrrr commented May 26, 2021

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

@xpusostomos

This comment has been minimized.

Copy link

@xpusostomos 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

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