Important note
This is the first
release of this brand new technology and it is branded “beta”
deliberately – it’s not yet complete! We know there are issues and
incomplete features, you should expect some things to work and for many
things to fail. But we appreciate you playing with this feature and
helping us identify the issues we need to fix in order to deliver a
great experience.
Overview
Windows provides developers with a familiar Bash environment. This environment will allow users to:
Run common command-line utilities such as grep
, sed
, and awk
Navigate the file system using these commands
Run Bash shell scripts which rely on supported command-line utilities
Windows
is running Ubuntu user-mode binaries provided by Canonical. This means
the command-line utilities are the same as those that run within a
native Ubuntu environment.
Installation of Bash on Windows is just a few clicks.
This
is provided as beta software. While many of the coreutil commands
provided by Ubuntu will work, there are some that will not. We welcome
feedback and will prioritize accordingly.
This video from Build 2016 gives you more information and a demo of Ubuntu on Windows:
Get started
VIDEO
Installation Guide
Your PC must be running a 64-bit version of Windows 10 Anniversary Update build 14393 or later
To find your PC's CPU architecture and Windows version/build number, open
Settings >System >About .
Look for the OS Build and System Type fields.
If your build is below 14393, try checking for updates.
Installation
In order to run Bash on Windows, you will need to manually:
Turn-on Developer Mode
Enable the "Windows Subsystem for Linux (beta)" feature via the GUI or the command-line:
Turn on Developer Mode
Open Settings -> Update and Security -> For developers
Select the Developer Mode radio button
Enable the Windows Subsystem for Linux feature (GUI)
From Start, search for "Turn Windows features on or off" (type 'turn')
Select Windows Subsystem for Linux (beta)
Click OK
Enable the Windows Subsystem for Linux feature (command-line)
Open a PowerShell prompt as administrator and run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-
Subsystem-Linux
After enabling Windows Subsystem for Linux
Restart your computer when prompted
It is important that you DO restart when prompted as some of the infrastructure which Bash on Windows requires can only be loaded during Windows' boot-up sequence.
Run Bash on Windows
Open a command prompt
Run bash
After
you have accepted the License, the Ubuntu user-mode image will be
downloaded and a "Bash on Ubuntu on Windows" shortcut will be added to
your start menu.
To launch Bash on Windows, either run
bash
at a cmd/PowerShell command-prompt, or use the start menu shortcut.
After installation your Linux distribution will be located at:
%localappdata%\lxss\
This directory is marked as a hidden system folder for a very good reason:
Avoid creating and/or modifying files in this location using Windows tools
and apps! If you do, it is likely that your Linux files will be corrupted and data loss may occur.
Please read this blog post
for more information.
Create a UNIX user
The first time you install Bash on Windows, 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.
Command Reference
The commands
bash.exe
and
lxrun.exe
are used to interact with the
Windows Subsystem for Linux (WSL) .
These commands are installed into the \Windows\System32 directory and
may be run within a Windows command prompt or in PowerShell.
bash.exe
launches the Bash environment and invokes /bin/bash.
lxrun.exe
is used to manage WSL. This command can be used to install or uninstall the Ubuntu image.
Command Description
bash
Launches the Bash shell in the current directory. If the Bash shell is not installed automatically runs lxrun /install
bash ~
Launches the bash shell into the user's Ubuntu home directory. Similar to running cd ~
bash -c "<command>"
Runs the command, prints the output and exits back to the Windows command prompt.
Example: bash -c "ls"
Command Description
lxrun
The lxrun command is used to manage the WSL instance.
lxrun /install
Starts the download and install process.
/y may be added to bypass all prompts. The confirmation prompt is automatically accepted and the default user is set to root.
lxrun /uninstall
Uninstalls and deletes the Ubuntu image. By default this does not remove the user's Ubuntu home directory.
/y may be added to automatically accept the confirmation prompt
/full uninstalls and deletes the user's Ubuntu home directory
lxrun /setdefaultuser <userName>
Sets
the default Bash on Ubuntu user. Will prompt for a password if the
specified user does not exist. For more information visit: http://aka.ms/wslusers .
/y Bypasses promping for the password. The user will be created without a password.
Linux User Account and Permissions
Bash on Ubuntu on Windows will prompt to create a default Linux user on first run. This user:
Does
not need to have the same username as the Windows signed in user and is
treated as a distinct entity from the Windows user account
Will be prompted for a new password
Password will be used for Linux commands such as sudo
and not used by any system outside of WSL
Will be automatically added to the sudo group
Will be signed-in automatically for every Bash instance
Will not require a password when launching WSL
Each
Windows user has a unique WSL instance. This means all changes made
within the WSL environment are unique to that Windows user. This
includes Bash users created with the
adduser
command.
Users may change their default Bash user with the
lxrun /setdefaultuser
command. Users who have a previous build may use lxrun to set their
default user without having to uninstall. The default user ‘root’ is
valid for users who would like to run directly as root, or require root
access for troubleshooting. Setting the default user to ‘root’ does not
require a password.
Permissions
There are two important concepts to keep in mind when it comes to permissions:
The Windows permission model, i.e. administrator
The Linux permission model, i.e. root access
When Bash runs, it has the same permissions as the console. This means if typing
bash
from a normal CMD or PowerShell prompt, it is given the same permissions as the logged-in Windows user. Running
bash
from an “elevated” or “Administrator” command prompt then runs Bash with elevated permissions.
This
is independent of the signed-in Linux user account. Root privileges on
the Linux side only impact the user’s rights within the Linux
environment & filesystem; they have no impact on the Windows
privileges granted.
Example:
A Bash session with Windows admin privileges may cd /mnt/c/Users/Administrator
while a Bash session without admin privileges would see Permission Denied.
Typing sudo cd /mnt/c/Users/Administrator
will not grant access to the Administrator’s directory since the permissions are restricted by Windows.
The
Linux permission model is important when inside the Ubuntu environment
where the user has permissions based on the current Linux user.
Example:
A user in the sudo group may run sudo apt update