![](http://1.bp.blogspot.com/-5UaEUZJ6D_8/WYvjfEQmvBI/AAAAAAAAO68/y6FXaCML1loPk4Gpwyu5rqG5RF-P2HSEgCLcBGAs/s1600/WindowsSubsystemforLinuxWindowsServer.png)
This guide help you become a Windows Insider, download Windows Server, and get Linux running on the Windows Subsystem for Linux.
Prerequisites
Windows Server 2016 (build 16215+). Right now, that means a Windows Insider's build.
Join Windows Insiders and Download Windows Server
- Join a Windows Insiders program:
- Download Windows Server 2016 - Insider Preview.
Make sure you're logged in, images are only available to Windows Insiders.
Set up Windows Server
Now that you have a Windows Server image (.iso), install Windows Server on a physical computer or a virtual machine. I'm going to use a virtual machine on Hyper-V.During installation, Windows Server will ask for a product key. The following keys are available for unlimited activation of Windows Server (pre-release builds only). These keys may be used throughout the pre-release cycle. Read more here.
- Server Datacenter Core: B69WH-PRNHK-BXVK3-P9XF7-XD84W
- Server Standard Core: V6N4W-86M3X-J77X3-JF6XW-D9PRV
When you're done, you should see something like this:
![](http://2.bp.blogspot.com/-zVoA683rEcQ/WYvglujzrFI/AAAAAAAAO6o/YuvEzxLn614Rh2YslRF-yYWWCs0NQM0wQCLcBGAs/s1600/WindowsSubsystemforLinuxWindowsServer-0.png)
Check your build number
To find your Windows Server build number, run the following in PowerShell:
systeminfo | Select-String"^OS Name","^OS Version"
You can also confirm that your build has the Windows Subsystem for Linux by running the following in PowerShell:
PowerShell
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable the Windows Subsystem for Linux
Enable the "Windows Subsystem for Linux" optional feature and reboot.
- Open PowerShell as Administrator and run:
PowerShell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux - Restart your computer when prompted.
Install a Linux distribution
- Download the appx for your favorite Linux distribution.
Here are links directly to the apps available through the store:- Ubuntu
- OpenSUSE
- You can download the distributions to Windows Server with
Invoke-WebRequest
cmdlet. Here's a sample instruction to download OpenSUSE.PowerShell
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile ~/Ubuntu.zip -UseBasicParsingTip: If the download is taking a long time, turn off the progress bar by setting$ProgressPreference = 'SilentlyContinue'
- Unzip the file
Expand-Archive ~/Ubuntu.zip ~/Ubuntu
Make sure your target directory (~/Ubuntu
in this example) is on your system drive. Usually this is your C: drive.
Example:C:\Distros\Ubuntu
The contents should look like this:
![](http://1.bp.blogspot.com/-s-GDzW66Ze4/WYvgl0hBh2I/AAAAAAAAO6w/3Ptls8_s9xIiqj1xoNkdL1dwvfpaE8KRgCLcBGAs/s1600/WindowsSubsystemforLinuxWindowsServer-1.png)
3. Run the installer, named
For example:
.exe
For example:
ubuntu.exe
, fedora.exe
, etc.Troubleshooting: Installation failed with error 0x8007007e
This error occurs when your system doesn't support Linux from the store. Make sure that:
- You're running Windows build 16215 or later. Check your build.
- The Windows Subsystem for Linux optional component is enabled. Instructions here.
4. Create a UNIX user
The first time you install the Windows Subsystem for Linux, you will be prompted to create a UNIX username and password.
This UNIX username and password can be different from, and has no relationship to, your Windows username and password.
5. Run distro's preferred update/upgrade.
sudo apt-get update
sudo apt-get upgrade
You're done! Go use your new Linux environment!
![](http://1.bp.blogspot.com/-js5OxDawBUA/WYvgl7CPbsI/AAAAAAAAO6s/SGFZzdTb4nUXM4ivSvM8IfK68xKCS__xgCLcBGAs/s1600/WindowsSubsystemforLinuxWindowsServer-2.png)
Windows Interoperability
This interoperability functionality delivers a seamless experience between Windows and WSL.
Invoking WSL from the Windows Command Line
Linux binaries can be invoked from the Windows Command Prompt or from PowerShell. Binaries invoked in this way have the following properties:
- Use the same working directory as the CMD or PowerShell prompt.
- Run as the WSL default user.
- Have the same Windows administrative rights as the calling process and terminal.
Example:
C:\temp>bash -c "ls -la"
total 916
drwxrwxrwx 2 root root 0 Sep 28 08:45 .
drwxrwxrwx 2 root root 0 Sep 27 07:33 ..
-rwxrwxrwx 1 root root 14 Sep 27 14:26 foo.bat
Linux commands called in this way are handled like any other Windows application. Things such as input, piping, and file redirection work as expected.
Examples:
C:\temp>bash -c "sudo apt-get update"
[sudo] password for username:
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
C:\temp>bash -c "ls -la" | findstr foo
-rwxrwxrwx 1 root root 14 Sep 27 14:26 foo.bat
C:\temp>dir | bash -c "grep foo"
09/27/2016 02:26 PM 14 foo.bat
C:\temp>bash -c "ls -la"> out.txt
The WSL commands passed into
bash -c
are forwarded to the WSL process without modification. File paths must be specified in the WSL format and care must be taken to escape relevant characters. Example:C:\temp>bash -c "ls -la /proc/cpuinfo"
-r--r--r-- 1 root root 0 Sep 28 11:28 /proc/cpuinfo
C:\temp>bash -c "ls -la \"/mnt/c/Program Files\"”
<- -="" c:="" contents="" files="" of="" rogram="">
->
Invoking Windows binaries from WSL
The Windows Subsystem for Linux can invoke Windows binaries directly from the WSL command line. Applications run this way have the following properties:
- Retain the working directory as the WSL command prompt except in the scenario explained below.
- Have the same permission rights as the
bash.exe
process. - Run as the active Windows user.
- Appear in the Windows Task Manager as if directly executed from the CMD prompt.
Example:
$/mnt/c/Windows/System32/notepad.exe
In WSL, these executables are handled similar to native Linux executables. This means adding directories to the Linux path and piping between commands works as expected. Examples:
$ export PATH=$PATH:/mnt/c/Windows/System32
$ notepad.exe
$ ipconfig.exe | grep IPv4 | cut -d: -f2
$ ls -la | findstr.exe foo.txt
$ cmd.exe /c dir
The Windows binary must include the file extension, match the file case, and be executable. Non-executables including batch scripts and command like
dir
can be run with /mnt/c/Windows/System32/cmd.exe /C
command. Examples:$ /mnt/c/Windows/System32/cmd.exe /C dir
$ /mnt/c/Windows/System32/PING.EXE www.microsoft.com
Parameters are passed to the Windows binary unmodified.
As an example, the following commands will open
C:\temp\foo.txt
in notepad.exe
:$notepad.exe “C:\temp\foo.txt”
$notepad.exe C:\\temp\\foo.txt
Modifying files located on VolFs (files not under
/mnt/
) with a Windows application is not supported. By default, WSL attempts to keep the working directory of the Windows binary as the current WSL directory, but will fall back on the instance creation directory if the working directory is on VolFs.As an example;
bash.exe
is initially launched from C:\temp
and the current WSL directory is changed to the user’s home. When notepad.exe
is called from the user’s home directory, WSL automatically reverts to C:\temp
as the notepad.exe working directory:C:\temp>bash
/mnt/c/temp/$ cd ~
~$ notepad.exe foo.txt
~$ ls | grep foo.txt
~$ exit
exit
C:\temp>dir | findstr foo.txt
09/27/2016 02:15 PM 14 foo.txt
Users may disable the ability to run Windows binaries for a single WLS session by running the following command as root:
$ echo 0 > /proc/sys/fs/binfmt_misc/WSLInterop
To reenable Windows binaries either exit all WSL sessions and re-run bash.exe or run the following command as root:
$ echo 1 > /proc/sys/fs/binfmt_misc/WSLInterop
Note that disabling interop will not persist between WSL sessions.