Use X11 forwarding with WSL

From IIHE Wiki
Revision as of 15:22, 2 August 2021 by Root (talk | contribs)
Jump to navigationJump to search


This page will help you to install Windows Subsystem for Linux and X11 forwarding on Windows 10.
Windows Subsystem for Linux can run a complete Linux OS inside Windows.
VCXSVR will help you to have X11 forwarding enabled.

Starting from Windows 10 build 2004 you can install WSL2 & a Linux distro from an elevated prompt in one command, more info here.


  • Windows 10 version or more recent.
  • Administrative rights on your computer.
  • Chocolatey, the Windows package manager installed.

Install Chocolatey

Open a Powershell shell as Administrator by pressing the following keys :

  • Windows key + X

WSL Start Powershell As Admin.PNG

Paste the following in the Powershell window :

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(''))

Once Chocolatey is installed close the Powershell window.

More detail is available here

Install WSL2 & VCXSVR

Open a Powershell shell as Administrator by pressing the following keys :

  • Windows key + X

WSL Start Powershell As Admin.PNG

On the Powershell window type the following :

  • choco install vcxsrv wsl2 -y

This command will enable WSL2 and install VCXSRV to enable X11 forwarding.

Leave the Powershell window open since we still need it to install your distribution.

Install your Linux distro on WSL

Now you need to choose witch distro you want to install on your computer :

  • Ubuntu 18.04
  • Ubuntu 16.04
  • Debian GNU/Linux
  • Kali Linux
  • openSUSE 42.2 (Malachite)
  • SUSE Linux Enterprise Server 12 SP2
  • Fedora Remix for WSL

Once you choose the distro you can download and install it in one Powershell command :

  • (To download and install) Ubuntu 18.04


choco install wsl-ubuntu-1804 -y

  • Ubuntu 16.04

choco install wsl-ubuntu-1604 -y

  • Debian GNU/Linux

choco install wsl-debiangnulinux -y

  • Kali Linux

choco install wsl-kalilinux -y

  • openSUSE 42.2 (Malachite)

choco install wsl-opensuse -y

  • SUSE Linux Enterprise Server 12 SP2

choco install wsl-sles -y

  • Fedora Remix for WSL

choco install wsl-fedoraremix -y

Starting The distro

  • Once you installed the distro you can start it from the Start menu :

WSL Debian Start Menu.PNG

  • You have to set a username and password Note that you can't use the same username as your Windows username:

WSL Create User Name.PNG

WSL Init Success.PNG

  • Let's update the software on the distro (Debian or Ubuntu) :

sudo apt update && sudo apt upgrade -y

WSL Upgrade.PNG

  • Install X11 apps to test X11 Forwarding :

sudo apt install x11-apps -y

  • Enable X11 forwarding :

echo "export DISPLAY=localhost:0.0" >> ~/.bashrc

  • Now exit your terminal and start the distro again.
  • Start VCXSRV on Windows and start xclock on the distro terminal :


WSL Xclock Running.PNG

You should see a clock appears on Windows.

  • Now you have a complete Linux distro installed on Windows 10 and X11 forwarding enabled.

Installing using WSL.exe

From Windows build 2004 you can now install WSL2 and a Linux distro directly from an elevated command prompt using WSL.exe.

  • Note that you need an up to date Windows 10 starting from Build 2004 and the update KB5004296 installed.
  • If you want to install Ubuntu LTS just type the following from an elevated command prompt :

wsl --install

This command will setup WSL2 and install Ubuntu LTS.

  • If you you want to list available distros use the following command :

wsl --list --online

  • Once you choose the distro that you want to install use the following command :

wsl --install -d <DistroName>

(replace <DistroName> with the name of the distro you want to install eg "wsl --install -d debian".)

  • After the script complete you need to restart your computer.