How to Install WSL on Windows Server

How to Install WSL on Windows Server

WSL allows you to run applications natively as Linux processes on Windows. Learn how to install and use WSL on Windows Server here.

Which versions of Windows Server support WSL?

According to Microsoft documentation, the Windows Subsystem for Linux (WSL) is available for installation on Windows Server 2019 (1709) and above. This includes the few Windows Server Semi-Annual Channel (SAC) releases (versions 1909, 2004, 20H1, 20H2, etc.) and Windows Server 2022.

For more information on how to run Linux GUI apps using WSL, check out How to Install Linux GUI Apps in Windows 10 and Windows 11 with WSL on Petri.

How does installing WSL differ on Windows Server?

Well, this is an interesting question. Depending on what version of Windows Server you’re using will dictate how you install WSL. And, unfortunately, there is one underlying platform difference in running WSL on Windows Server vs Windows 10 and Windows 11.

As you’ll read at the end of my post, WSL 2 distributions are not available and not supported on Windows Server 2019 and 2022. Aside from that glaring omission, there are no other real differences in using WSL on Windows Server vs. say Windows 10 or Windows 11. It’s similar to Hyper-V. Enabling Hyper-V on Windows 10 and 11, and Windows Server is very similar. Once it’s installed, you fire up the Hyper-V Manager and start building virtual machines (VM). This is the same with WSL on Windows client or Windows Server.

Install the Windows Subsystem for Linux in Windows Server

Remember what I said about the differences in how you install WSL on Windows Server? This will be a wonderful example of the advances Microsoft has made with installing WSL in Windows Server 2019 and Windows Server 2022. To all the Linux fans out there…this might just persuade you to build a few Windows Server 2022 servers to play around with. 

Install WSL in Windows Server in 3 steps:

  1. Install the WSL optional feature using PowerShell
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  2. Enable the Virtual Machine Platform
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  3. Download and run the Linux kernel update package.

Now let’s look at the process in more detail for Windows Server 2019 and Windows Server 2022.

WSL in Windows Server 2019

Step #1. Install the optional feature, Windows Subsystem for Linux, via PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Installing WSL feature via PowerShell
Installing WSL feature via PowerShell

After this completes, press ‘Y’ to restart your server.

Step #2. We need to enable the Virtual Machine Platform feature by running this command:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Enabling the Virtual Machine Platform feature via 'dism' command
Enabling the Virtual Machine Platform feature via ‘dism’ command

Go ahead and reboot for safe measure.

Step #3. Download and run the Linux kernel update package.

Installing the Linux kernel update package
Installing the Linux kernel update package

Note: Windows Server versions/SKUs do not support WSL version 2 distributions. However, you can still use WSL version 1 for all your distributions.

WSL in Windows Server 2022

Alright, so, this may give you a chuckle…open an administrative PowerShell window or command prompt and run this fabulous command!

wsl --install
One command handles 3 or 4 steps like magic!
One command handles 3 or 4 steps like magic!

That’s right. This single command installs the Virtual Machine Platform feature, the Windows Subsystem for Linux, and downloads an Ubuntu distribution for you! Next, reboot.

After a reboot, the Ubuntu distribution starts to load. But, before we continue with that, we first need to update the kernel for WSL by running this command:

wsl --update

If that doesn’t work for whatever reason, you can run the Linux kernel update package from above.

But then, we run into an issue that has been around since the various Insider preview builds of Windows Server 2022 earlier in 2021. When you try to change the default version for distributions to ‘2’, the command simply doesn’t work. Even the help included with ‘wsl’ shows the command to use. Yet, I have never been able to make this work. I ran this command to first check status:

wsl --status
Getting the status of your WSL environment
Getting the status of your WSL environment

Then, I tried the version command:

wsl --set-default-version 2
Unfortunately, Windows Server does not support enabling WSL version 2
Unfortunately, Windows Server does not support enabling WSL version 2

As you can see from the output, Windows interprets it as an incorrectly formed command. Yet, below in the help file, you can see the exact command I ran! Anyway, as you’ll see at the end of this article, I discovered through more digging than I feel is necessary the fact that ‘WSL 2’ is not compatible with Windows Server at all. It’s not a terribly huge deal, but it’s disappointing nonetheless. Well, let’s move on!

Download a Linux distribution

Again, I’ll show you the basics here depending on what version of Windows Server you’re using. You can do everything from the ‘wsl’ command in 2022, but there are manual steps if you’re running 2019. Microsoft documentation includes the various download links to distributions but PowerShell, again, simplifies things for us. For example, to download ‘Ubuntu 20.04’, open PowerShell and type:

Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing

If you’re using Windows Server 2022, you can list the available distributions using the ‘wsl’ command again:

wsl --list --online
Easy way to list the available distributions for download/install
Easy way to list the available distributions for download/install

And to download and install for example SUSE Linux Enterprise Server v12, type this:

wsl --install -d SLES-12

Install a Linux distribution on Windows Server

After the download completes, run these PowerShell commands to rename the file, and then extract the contents:

Rename-Item .\Ubuntu.appx .\Ubuntu.zip
Expand-Archive .\Ubuntu.zip .\Ubuntu

To install the distribution, simply run the ‘ubuntu2004.exe’ file.

Extracting the download file for your new distribution
Extracting the download file for your new distribution

Launch and log in to your Linux distribution

There are various methods you can use to launch your distributions. And yes, efficiencies abound in 2022 vs 2019. In Windows Server 2022, each distribution you install gives you a shortcut in your Start Menu. In Windows Server 2019, there are ways to manually create that shortcut. But, an easy way is to just run the name of the distribution at a command prompt. The first step is to create your UNIX user account.

After entering your UNIX username and giving it a password, you are done! You have free reign over this ‘container‘ process that runs a pseudo virtualization infrastructure under the hood. It is very lightweight and it essentially allows you to run a real Linux kernel in Windows!

Initial configuration of Ubuntu 20.04
Initial configuration of Ubuntu 20.04

Let me finish this post by giving you a suggestion to update all the software packages in your distribution. Run these commands to achieve this:

sudo apt-get update
sudo apt-get upgrade
Running 'apt-get update' and 'apt-get upgrade' in Ubuntu 20.04
Running ‘apt-get update’ and ‘apt-get upgrade’ in Ubuntu 20.04

And there you have it! I must say, if you’re familiar with WSL and have used WSL 2 (version 2) distributions on Windows 10 or Windows 11, you’ll right away notice the slower disk I/O inherent in WSL 1 distributions. As of this writing, I am unable to convert my distributions on Windows Server 2022 to version 2. It’s a shame.

WSL 2 is not supported in Windows Server 2019 or Windows Server 2022

Late-breaking update: I finally did find on GitHub a post by a Microsoft engineer/PM stating that WSL 2 distributions are NOT supported on Windows Server. Oh well…