In this blog post, I’ll show you how to use the Windows Subsystem for Linux (WSL) and run Linux commands, tools and application directory on Windows Server 2016.
To show you how powerful WSL is, I’ll Install the Nginx Web Server and run it In a matter of minutes.
Windows Subsystem for Linux (WSL)
Announced at Build 2017 and currently only available on Windows Server Insider builds, The Windows Subsystem for Linux allows developers run Linux command-line tools, applications, and utilities directly on Windows Server without using a virtual machine, Containers, etc.
To run WSL you don’t even need to Install the Hyper-V roles, WSL works natively on Windows Server as a Server Role.
To get started, with WSL, I recommend you disable the Firewall on the Server because Nginx needs port 80 to be open.
Set-NetFirewallProfile -Profile Domain, Public,Private -Enabled false
To check your Windows Insider build number run the cmdlet below (you will also notice that Windows Insider uses new colors In the PowerShell window)
systeminfo | Select-String "^OS Name","^OS Version"
To Install the WSL role, Run the cmdlet below and restart the Server when completed
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
When the server comes online, Download the Ubuntu Server build using the cmdlet below.
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile ~/Ubuntu.zip -UseBasicParsing
Once download, unzip the build using the cmdlet below:
Expand-Archive .\Ubuntu.zip c:\ubuntu
Below you can see the files
To run Ubuntu simply run the line below from the Ubuntu folder
The first thing you will be asked to do is to create a Unix user account, Make sure the user is not the same as your windows account
To exit the WSL, type exit and to enter it again run the .EXE file again
Note: You could download the Linux Command Line Guide I have written back In 2013 for this post.
To install Nginx Web Server, enter WSL and run the update command below to patch Ubuntu first.
To Install Nginx run
apt-get install Nginx
And to start it after Installation run
sudo /etc/init.d/nginx start
To view, edit the Nginx configuration file go to the configuration folder from WSL
There is no doubt the WSL will make it so much easier for Windows admins use Linux for testing, development or just run tools that are not available on Windows Server.
In the past getting Linux configured was an annoying task because you had to setup a full VM and configure it with IP, DNS, etc.
WSL takes all the overhead and allows you to run Linux on Windows In the easiest, clean and supported way.