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
, modifyingbash.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
- 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.
- 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.
- Run
dbus-launch --exit-with-session gnome-session
- Go to the full-screen VcXsrv window. The Ubuntu GNOME desktop should show up now. Enjoy!
- 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!