Windows Subsystem for Linux

Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10. This means you can download an executable compiled for Linux and run it unmodified under Windows. You can also `apt install` the entire repertoire of Ubuntu packages, or pick a different distribution such as Fedora and openSUSE from Windows Store. Follow the official guide to install.

  • NOTE Install WSL1 unless you know you absolutely need WSL2. WSL1 and WSL2 serve different use cases. WSL1 is NOT an older version of WSL2. WSL1 translates Linux system calls to Windows system calls while WSL2 runs a Hyper-V virtual machine. At present, WSL1 works better for our purposes. WSL2 has slower filesystem performance accessing files from the Windows side and unresolved memory leaking problem.
  • NOTE If you do install WSL1, choose Ubuntu 22.04 LTS, which works well with the Linux 4.4.0 kernel WSL1 mimics. Later versions use glibc libraries that target newer Linux kernels.
wsl --set-default-version 1
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile Ubuntu2204.appx -UseBasicParsing
Add-AppxPackage .\Ubuntu2204.appx
ubuntu2204.exe
wsl --set-version Ubuntu 1
Remove-Item .\Ubuntu2204.appx

X11 and DBus

Since WSL does not currently support X11 and Unix sockets, which DBus uses by default, we need to do the following:

  • Install VcXsrv or Xming.
  • Suppress a few benign warnings:
echo "export NO_AT_BRIDGE=1" >> ~/.bashrc
sudo sh -c 'dbus-uuidgen > /etc/machine-id'
  • You may also create a shortcut (e.g., by right clicking on Desktop -> New -> Shortcut), and enter C:\path\to\VcXsrv\vcxsrv.exe :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl as the target. You may then copy this shortcut to %AppData%\Microsoft\Windows\Start Menu\Programs\Startup so that it automatically runs when the OS boots up.

There are 2 versions of WSL available, namely WSL1 and WSL2. To determine the version installed on your computer, open Command Prompt and execute wsl -l -v. Depending on the version, one needs to follow the corresponding steps:

WSL1

  • export DISPLAY=localhost:0.0. You can add this to your shell init script:
echo "export DISPLAY=localhost:0.0" >> ~/.bashrc
  • In /etc/dbus-1/session.conf, replace unix:tmpdir=/tmp with tcp:host=localhost,port=0. If the file or the line does not exist, simply add it.

WSL2

You need to add this to your .bashrc file

export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export LIBGL_ALWAYS_INDIRECT=1

Comments

Comments powered by Disqus