Installing Ubuntu to Windows Server 2019 (WSL)

Installing Ubuntu to Windows Server 2019 (WSL)

Open up an (elevated) Powershell instance and run the following script. It will download Ubutu and enable the Linux Subsystem on Windows.

# download Ubuntu
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile Ubuntu.zip -UseBasicParsing

# extract the file
Expand-Archive ./Ubuntu.zip ./Ubuntu

# set path
$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + $(Get-Location).Path + "\Ubuntu", "User")

# install WSL:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Now that everything is in place, please restart the server. After the restart, open up Powershell again and run Ubuntu. You will be asked to create a new UNIX user.

cd Ubuntu
ubuntu1604.exe

Now you can upgrade to the latest version of Ubuntu by this script:

sudo apt-get update
sudo apt-get upgrade

It might take some time to upgrade.

Improvements

2019-06-24: Changed the out file for the download link into a zip extension, no renaming needed anymore. 2018-06-24: The executable in the current download is ubuntu1604.exe, so I changed it in the script.