Use X11 forwarding with WSL: Difference between revisions

From IIHE Wiki
Jump to navigationJump to search
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
==About==
==About==
This page will help you to install Windows Subsystem for Linux and X11 forwarding on Windows 10.<br />
This page will help you to install Windows Subsystem for Linux and X11 forwarding on Windows 10 or Windows 11.<br />
Windows Subsystem for Linux can run a complete Linux OS inside Windows.<br />
Windows Subsystem for Linux can run a complete Linux OS inside Windows.<br />
VCXSVR will help you to have X11 forwarding enabled.<br />
VCXSVR will help you to have X11 forwarding enabled.<br />
'''Starting from Windows 10 build 2004 you can install WSL2 & a Linux distribution from an elevated prompt in one command, more info [https://wiki.iihe.ac.be/index.php?title=Use_X11_forwarding_with_WSL#Installing_using_WSL.exe here].'''
=Windows 10=


==Pre-requities==
==Pre-requities==


*Windows 10 version or more recent.
*Windows 10 Windows 11.
*Administrative rights on your computer.
*Administrative rights on your computer.
*Chocolatey, the Windows package manager installed.
*Chocolatey, the Windows package manager installed.
Line 24: Line 28:
Once Chocolatey is installed close the Powershell window.
Once Chocolatey is installed close the Powershell window.


More detail is [https://chocolatey.org/install available here]
More info about Chocolatey is [https://chocolatey.org/install available here]


==Install WSL & VCXSVR==
==Install WSL1 & VCXSVR==


Open a Powershell shell as Administrator by pressing the following keys :
Open a Powershell shell as Administrator by pressing the following keys :
Line 36: Line 40:
On the Powershell window type the following :
On the Powershell window type the following :


*<code>choco install vcxsrv wsl -y</code>
*<code>choco install vcxsrv microsoft-windows-terminal wsl -y</code>
 
This command will install Windows Terminal, VCXSRV and enable WSL to enable X11 forwarding.


This command will enable WSL 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==
==Install your Linux distribution on WSL==


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


*'''Ubuntu 18.04'''
*'''Ubuntu 18.04'''
*'''Ubuntu 18.04 ARM'''
*'''Ubuntu 20.04'''
*'''Ubuntu 16.04'''
*'''Ubuntu 22.04'''
*'''Debian GNU/Linux'''
*'''Debian GNU/Linux'''
*'''Kali Linux'''
*'''Kali Linux'''
*'''OpenSUSE Leap 42'''
*'''openSUSE 42.2 (Malachite)'''
*'''SUSE Linux Enterprise Server 12'''
*'''SUSE Linux Enterprise Server 12 SP2'''
*'''Fedora Remix for WSL'''
*'''Fedora Remix for WSL'''


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


* (To download and install) '''Ubuntu 18.04'''
* (To download and install) '''Ubuntu 18.04'''
Line 59: Line 65:
USE :
USE :


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu1804.appx -UseBasicParsing; Add-AppxPackage .\Ubuntu1804.appx</code>
<code>choco install wsl-ubuntu-1804 -y</code>


*'''Ubuntu 18.04 ARM'''
*'''Ubuntu 20.04'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804-arm -OutFile Ubuntu1804arm.appx -UseBasicParsing; Add-AppxPackage .\Ubuntu1804arm.appx</code>
<code>choco install wsl-ubuntu-2004 -y</code>


*'''Ubuntu 16.04'''
*'''Ubuntu 22.04'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu1604.appx -UseBasicParsing; Add-AppxPackage .\Ubuntu1604.appx</code>
<code>choco install wsl-ubuntu-2204 -y</code>


*'''Debian GNU/Linux'''
*'''Debian GNU/Linux'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-debian-gnulinux -OutFile Debian.appx -UseBasicParsing; Add-AppxPackage .\Debian.appx</code>
<code>choco install wsl-debiangnulinux -y</code>


*'''Kali Linux'''
*'''Kali Linux'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-kali-linux-new -OutFile Kali.appx -UseBasicParsing; Add-AppxPackage .\Kali.appx</code>
<code>choco install wsl-kalilinux -y</code>


*'''OpenSUSE Leap 42'''
*'''openSUSE 42.2 (Malachite)'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-opensuse-42 -OutFile Opensuse.appx -UseBasicParsing; Add-AppxPackage .\Opensuse.appx</code>
<code>choco install wsl-opensuse -y</code>


*'''SUSE Linux Enterprise Server 12'''
*'''SUSE Linux Enterprise Server 12 SP2'''


<code>Invoke-WebRequest -Uri https://aka.ms/wsl-sles-12 -OutFile Opensuse.appx -UseBasicParsing; Add-AppxPackage .\Opensuse.appx</code>
<code>choco install wsl-sles -y</code>


*'''Fedora Remix for WSL'''
*'''Fedora Remix for WSL'''


You have to first get the appx file here : https://github.com/WhitewaterFoundry/WSLFedoraRemix/releases/
<code>choco install wsl-fedoraremix -y</code>
Once you got the file you can install it using : <code>Add-AppxPackage <packagepath>\<packagename></code>


==Starting The distro==
==Starting The distribution==


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


[[Image:WSL_Debian_Start_Menu.PNG]]
[[Image:WSL_Debian_Start_Menu.PNG]]
Line 102: Line 107:
[[Image:WSL_Init_Success.PNG|820x420px]]
[[Image:WSL_Init_Success.PNG|820x420px]]


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


<code>apt update && sudo apt upgrade -y</code>
<code>sudo apt update && sudo apt upgrade -y</code>


[[Image:WSL_Upgrade.PNG|820x420px]]
[[Image:WSL_Upgrade.PNG|820x420px]]
Line 116: Line 121:
<code>echo "export DISPLAY=localhost:0.0" >> ~/.bashrc</code>
<code>echo "export DISPLAY=localhost:0.0" >> ~/.bashrc</code>


*Now exit your terminal and start the distro again.
*Now exit your terminal and start the distribution again.


*Start VCXSRV on Windows and start xclock on the distro terminal :
*Start VCXSRV on Windows and start xclock on the distribution terminal :


[[image:WSL_Start_VCXSRV.PNG]]
[[image:WSL_Start_VCXSRV.PNG]]
Line 126: Line 131:
You should see a clock appears on Windows.
You should see a clock appears on Windows.


*Now you have a complete Linux distro installed on Windows 10 and X11 forwarding enabled.
*Now you have a complete Linux distribution installed on Windows 10 and X11 forwarding enabled.
 
=Windows 11=
 
==Installing using WSL.exe==
 
From Windows 11 & Windows 10 build 2004 and later you can install WSL2 and a Linux distribution directly from an elevated command prompt using WSL.exe.
 
*Note that you need an up to date Windows 11 or a Windows 10 starting from Build 2004 and the update KB5004296 installed.
 
*WSL2 does '''NOT''' need a X11 server to be installed on Windows to enable x11 forwarding, it will work out of the box.
 
*If you want to install Ubuntu LTS just type the following from an elevated command prompt :
 
<code>wsl --install</code>
 
This command will setup WSL2 and install Ubuntu LTS.
 
*If you you want to list available distributions use the following command :
 
<code>wsl --list --online</code>
 
*Once you choose the distribution that you want to install use the following command :
 
<code>wsl --install -d <distributionName></code>
 
(replace <DistributionName> with the name of the distribution you want to install eg "wsl --install -d debian".)
 
 
*After the script complete you need to restart your computer.
 
==Starting The distribution==
 
* Once you installed the distribution you can start it from the Start menu :
 
[[Image: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''':
 
[[Image:WSL_Create_User_Name.PNG|820x420px]]
 
[[Image:WSL_Init_Success.PNG|820x420px]]
 
* Let's update the software on the distribution (Debian or Ubuntu) :
 
<code>sudo apt update && sudo apt upgrade -y</code>
 
[[Image:WSL_Upgrade.PNG|820x420px]]
 
*Install X11 apps to test X11 Forwarding :
 
<code>sudo apt install x11-apps -y</code>
 
*Start xclock on Linux VM and start xclock on the distribution terminal :
 
[[image:WSL_Xclock_Running.PNG]]
 
You should see a clock appears on Windows.
 
*Now you have a complete Linux distribution installed on Windows and X11 forwarding enabled trough WSL2.

Latest revision as of 14:19, 8 November 2022

About

This page will help you to install Windows Subsystem for Linux and X11 forwarding on Windows 10 or Windows 11.
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 distribution from an elevated prompt in one command, more info here.

Windows 10

Pre-requities

  • Windows 10 Windows 11.
  • 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

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('https://chocolatey.org/install.ps1'))

Once Chocolatey is installed close the Powershell window.

More info about Chocolatey is available here

Install WSL1 & VCXSVR

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

  • Windows key + X

On the Powershell window type the following :

  • choco install vcxsrv microsoft-windows-terminal wsl -y

This command will install Windows Terminal, VCXSRV and enable WSL to enable X11 forwarding.

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

Install your Linux distribution on WSL

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

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

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

  • (To download and install) Ubuntu 18.04

USE :

choco install wsl-ubuntu-1804 -y

  • Ubuntu 20.04

choco install wsl-ubuntu-2004 -y

  • Ubuntu 22.04

choco install wsl-ubuntu-2204 -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 distribution

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

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

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

sudo apt update && sudo apt upgrade -y

  • 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 distribution again.
  • Start VCXSRV on Windows and start xclock on the distribution terminal :

You should see a clock appears on Windows.

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

Windows 11

Installing using WSL.exe

From Windows 11 & Windows 10 build 2004 and later you can install WSL2 and a Linux distribution directly from an elevated command prompt using WSL.exe.

  • Note that you need an up to date Windows 11 or a Windows 10 starting from Build 2004 and the update KB5004296 installed.
  • WSL2 does NOT need a X11 server to be installed on Windows to enable x11 forwarding, it will work out of the box.
  • 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 distributions use the following command :

wsl --list --online

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

wsl --install -d <distributionName>

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


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

Starting The distribution

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

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

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

sudo apt update && sudo apt upgrade -y

  • Install X11 apps to test X11 Forwarding :

sudo apt install x11-apps -y

  • Start xclock on Linux VM and start xclock on the distribution terminal :

You should see a clock appears on Windows.

  • Now you have a complete Linux distribution installed on Windows and X11 forwarding enabled trough WSL2.