Thursday, July 4, 2024
HomeOperating SystemsWindowsHow to run Linux on Windows Server 2019 with WSL

How to run Linux on Windows Server 2019 with WSL

Questions: How can I enable Windows Subsystem for Linux (WSL) feature on Windows Server 2019?. How do I use Linux on Windows Server 2019?. This guide will show you how to enable Windows Subsystem for Linux (WSL) feature on Windows server 2019 and run a Linux Server such as Ubuntu inside Windows Server. In our last article, we covered running Docker containers on Windows Server.

Use Windows Subsystem for Linux 03

The Windows Subsystem for Linux allows you to run GNU/Linux environment which includes most Linux command-line tools, utilities, and applications directly on your Windows system without any modification or overhead on the host system.

One pre-requisite is already installed Windows Server 2019. Lucky enough, we have a guide on the installation of Windows Server 2019.

Step 1: Enable Windows Subsystem for Linux (WSL)

Before you can install any Linux distribution for WSL, you must ensure that the “Windows Subsystem for Linux” feature is enabled:

Open PowerShell as Administrator and run the following command to enable Windows Subsystem for Linux (WSL) feature on Windows.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Agree to restart your computer when prompted.

Use Windows Subsystem for Linux 01

You can do the same from the Server Graphical Interfaces Server Manager>Add roles and features>Select features

Step 2: Install your Linux Distribution of Choice

There are various ways in which you can install WSL Linux distros via the Microsoft Store. In this guide, we will use download and install one from the Command-Line.

Launch PowerShell and download the distro with use the Invoke-WebRequest cmdlet or using curl.exe. Here’s a sample instruction to download Ubuntu 18.04.

curl.exe -L -o ubuntu-2004.appx https://aka.ms/wslubuntu2004

After the download, extract and install a Linux distro.

Rename-Item ubuntu-2004.appx ubuntu-2004.zip
Expand-Archive ubuntu-2004.zip ubuntu2004

Change your working directory to ubuntu2004 and run the installer to finish your distro installation.

cd ubuntu2004
.\ubuntu2004.exe 

The installer will prompt you to provide username and password for the UNIX user to be created.

Use Windows Subsystem for Linux 03

The sudo command can be used for privileged operations.

sudo apt update && sudo apt upgrade
sudo apt install ansible

Sample output:

Use Windows Subsystem for Linux 05

Add your distro path to the Windows environment PATH using Powershell:

$userenv = [System.Environment]::GetEnvironmentVariable("Path", "User")
[System.Environment]::SetEnvironmentVariable("PATH", $userenv + "C:\Users\Administrator\ubuntu2004", "User")

This will enable you to launch your distro from any path by typing the .exe launcher. For example using ubuntu2004.exe.

Note that this will require closing and relaunching PowerShell.

ubuntu2004.exe

See below

Use Windows Subsystem for Linux 06

There you go!. Enjoy using Linux distribution on your Windows Server. Other Linux distributions that you can run are:

The process of installing any of these distributions is same as one for Ubuntu 18.04.

Also check:

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments