Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!.
added 945 characters in body
Source Link
zzzhhh
  1. In cmd.exeInstall WSL + Ubuntu on a Windows machine of version 1903 or later (you don't need to be AdministratorI am using 22H2) of Windows.
    • Open Windows command line as Administrator. Run
      dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      
      to enable Windows Subsystem for Linux and Virtual Machine features.
    • Restart Windows to apply the above step. This step cannot be skipped.
    • Download WSL2 update package from here and install it. If you did not restart in the above step, you would receive error "This update only applies to machines with the Windows Subsystem for Linux" and "Windows Subsystem for Linux Update Setup Wizard ended prematurely".
    • Open Windows command line (you don't need to be Administrator this time) and run wsl --install -d ubuntu
    • Input UNIX username (i.e., Ubuntu username) and password in the prompt.
  2. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
    wsl --install -d ubuntu

Reboot Windows as required.

  1. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ./ubuntu-wsl2-systemd-script.sh
wsl --shutdown
wsl --update
wsl
  1. In cmd.exe (you don't need to be Administrator) of Windows, run
    wsl --install -d ubuntu

Reboot Windows as required.

  1. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
wsl --shutdown
wsl
  1. Install WSL + Ubuntu on a Windows machine of version 1903 or later (I am using 22H2).
    • Open Windows command line as Administrator. Run
      dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
      dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      
      to enable Windows Subsystem for Linux and Virtual Machine features.
    • Restart Windows to apply the above step. This step cannot be skipped.
    • Download WSL2 update package from here and install it. If you did not restart in the above step, you would receive error "This update only applies to machines with the Windows Subsystem for Linux" and "Windows Subsystem for Linux Update Setup Wizard ended prematurely".
    • Open Windows command line (you don't need to be Administrator this time) and run wsl --install -d ubuntu
    • Input UNIX username (i.e., Ubuntu username) and password in the prompt.
  2. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
./ubuntu-wsl2-systemd-script.sh
wsl --shutdown
wsl --update
wsl
Source Link
zzzhhh

This is end of 2023, WSL2, Ubuntu and GNOME is mature enough to start display manager automatically under basic.target when launching systemd. So, no need to modify ubuntu-wsl2-systemd-script. Below is a complete self-contained solution of WSL2 + Ubuntu GNOME connected via X forwarding. Please note that this answer is for X forwarding. If you wish to use Windows Remote Desktop to connect GNOME, please follow the working instructions here.

Environment:

  • Host: Dell desktop PC, CPU: i5-4690, memory: 16GB DDR3
  • Windows: Windows 10 22H2, Education 64 bit, [Version 10.0.19045.3693]
  • WSL2: 2.0.9.0
  • Guest OS: Ubuntu 22.04.3 LTS
  • GUI desktop: GNOME 42.9
  • X server: VcXsrv 1.20.14.0

Solution:

  1. In cmd.exe (you don't need to be Administrator) of Windows, run
    wsl --install -d ubuntu

Reboot Windows as required.

  1. When WSL2 + Ubuntu installation is done, in Ubuntu command line, run
sudo apt update
sudo apt-mark hold acpid acpi-support
sudo apt upgrade
  1. Install GNOME: sudo apt install ubuntu-desktop gnome.
  2. Install ubuntu-wsl2-systemd-script:
cd ~
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
bash ubuntu-wsl2-systemd-script.sh
  1. Exit WSL and Ubuntu by typing exit. In Windows command line, run
wsl --shutdown
wsl
  1. 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"
sudo mkdir -p /run/user/1000
sudo chmod 700 /run/user/1000
sudo chown $(whoami): /run/user/1000

  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.