A couple of months ago Microsoft announced the Windows Subsystem for Linux 2 (WSL 2), which is a successor of the Windows Subsystem for Linux shipped a couple of years ago. WSL 2 is currently available for Windows Insiders running Windows 10 Insider Preview Build 18917 or higher and with the Docker Tech Preview, you can now even run Docker Linux Container directly on WSL 2. With the latest Windows Server Insider Preview build 18945, you are also able to run WSL 2 on Windows Server. In this blog post, I am going to show you how you can install the Windows Subsystem for Linux 2 (WSL 2) on Windows Server. The Windows Subsystem for Linux was already available in earlier versions of Windows Server; however, WSL 2 brings a lot of new advantages. Be careful, this is running in preview and might not get into the official release and it is not supported in production.
The Windows Subsystem for Linux was in Windows 10 for a while now and allowed you to use different versions of Linux on your Windows 10 machine. With WSL 2, the architecture will change drastically and will bring increased file system performance and full system call compatibility. WSL 2 is now using virtualization technology (based on Hyper-V) and uses a lightweight utility VM on a real Linux kernel. You can find out more about WSL 2 in the release blog or on the Microsoft Docs Page for WSL 2.
Install Windows Subsystem for Linux 2 (WSL 2) on Windows Server
Here is how you can install WSL 2 on Windows Server.
Prerequisites:
- Windows Server Insider Preview build 18945 or higher
- A machine that supports Hyper-V Virtualization.
- If you are installing your Windows Server in a virtual machine, make sure Nested Virtualization is enabled.
After you have installed a new Windows Server with the Windows Server Preview build, you will need to add the following features:
- Microsoft-Windows-Subsystem-Linux
- VirtualMachinePlatform
To enable these features, run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
These commands will need a restart to complete.
Now you can install your Linux distribution which is available in WSL. You can also find the links to the Linux distro packages here: WSL distro packages. In my case, I am going to use Ubuntu 18.04, which is currently working with WSL 2.
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu1804.zip -UseBasicParsing md C:\Distros\Ubuntu1804 Expand-Archive ~/Ubuntu1804.zip C:\Distros\Ubuntu1804
Before you start and configure your WSL distro, I recommend that you set the WSL default version to 2. This will make the setup of your distro much faster.
wsl --set-default-version 2
Now you can start ubuntu.exe to run WSL.
C:\Distros\Ubuntu1804\ubuntu1804.exe
I hope this gives you a step-by-step guide on how you can install WSL 2 on Windows Server. Remember this is currently in preview, and not for production use. If you want to install the Windows Subsystem for Linux on Windows Server 2019, check out this blog post: Install Windows Subsystem for Linux on Windows Server.
Tags: Hyper-V, install, installation, Microsoft, Windows Server, Windows Server 2019, Windows Server Insider Preview, Windows Subsystem for Linux 2, Windows Subystem for Linux, WSL, WSL 2, WSL 2 on Windows Server, WSL on Windows Server Last modified: February 6, 2021
Ignore my previous comment. Figured it out.
PS C:\Windows\system32> wsl –set-version Ubuntu-18.04 2
Conversion in progress, this may take a few minutes…
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion complete.
PS C:\Windows\system32> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Stopped 2
Great that it worked! :)
Very cool information and simple walkthrough. FYI, 2 small typos in your shell scripts above referencing Ubuntu1894 instead of Ubuntu1804.
Thanks :) and thanks for letting me know about the typos. They should be fixed now :)
I cannot set wsl to version 2. Seems several options are not available. My wsl output is:
PS C:\Users\Administrator> wsl –set-version Ubuntu-20.04 2
Invalid command line option: –set-version
Usage: wsl.exe [option] …
Options:
-d, –distribution
Launch the specified distribition.
-e, –exec
Execute the specified Linux command. The remainder of the arguments are
used as the command line to execute.
-u, –user
Run as the specified user.
–help
Display this usage information.
—
Stop parsing arguments and pass the remainder to the Linux process.
OR
PS C:\Users\Administrator> wsl –set-default-version
Invalid command line option: –set-default-version
Usage: wsl.exe [option] …
Options:
-d, –distribution
Launch the specified distribition.
-e, –exec
Execute the specified Linux command. The remainder of the arguments are
used as the command line to execute.
-u, –user
Run as the specified user.
–help
Display this usage information.
—
Stop parsing arguments and pass the remainder to the Linux process.
Hi Marcelo
Which version of Windows 10 are you running?
hi, Thomas,
how can I install WSL2 on my Windows Server 2019?
Thanks.
Bose
Hi Thomas,
Thanks for the great blog! I was wondering if it would be possible to enable Docker to run Linux containers on Server insider (20215) with WSL2? I have been searching everywhere, but all tutorials are outdated on this.
Thanks,
Janjaap
Hi, might want to correct this article for those who are misled by it’s title. This is NOT for running WSL 2 on Windows Server, this is currently not possible. It’s for running WSL 2 on Windows 10.
You are wrong :) It is for running it on Windows Server. There is another post (see the link) for Windows 10.
I get the same response to wsl.exe commands not supporting the arguments in these instructions.
Running Windows Server 2019 Datacenter version 1809 build 17763.1637.
It’s running as a E Series V3 system on Azure.
I could not get this to run on any build of Windows Server 2019 following your directions – any thoughts? Similar to others I just get the WSL output of the various WSL options.
It doesn’t work with Windows Server 2019. You need “Windows Server Insider Preview build 18945 or higher”
Just a note for those who are trying now on Windows Server Preview (actual build 20287).
The WSL2 bits are broken from build 20251 onward.
Look here to download the last build where WSL2 works and don’t do an in-place upgrade.
https://techcommunity.microsoft.com/t5/windows-server-insiders/wsl-2-not-working-after-installing-20262/m-p/2109063/highlight/true?WT.mc_id=modinfra-0000-thmaure#M1601
Any news on this Thomas? What about Windows Server 2022?
Hi Thomas,
it would be a nice utopie – but in the actual WindowsServer2022 (v21H2, build 20348.202) – WSL2 seems not supported anymore. The so far well known ‘wsl –set-default-version 2’ run without any error nor effect – it sticks at WSL1. See that comment here: https://github.com/microsoft/WSL/issues/6301#issuecomment-858816891
That is a real pity, not only for your well explaining blog post. Can you confirm this?