# Installing Ubuntu to Windows Server 2019 (WSL)

**Date:** 2019-04-21  
**Author:** Kees C. Bakker  
**Categories:** Automation, bash, PowerShell, Windows  
**Tags:** WSL  
**Original:** https://keestalkstech.com/installing-ubuntu-to-windows-server-2019-wsl/

![Installing Ubuntu to Windows Server 2019 (WSL)](https://keestalkstech.com/wp-content/uploads/2019/04/ubuntu_logo-wallpaper-2048x1152-e1555832681103.jpg)

---

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

```powershell
# 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.

```powershell
cd Ubuntu
ubuntu1604.exe
```

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

```sh
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.
