Install Windows Subsystem for Linux on Windows 10
- 1 Installing a GNU userland
- 2 Setting up the GNU userland
- 2.1 Initial setup of the GNU userland
- 2.2 Setting up a root password (optional)
- 2.3 Update the system
- 2.4 Install some useful tools (optional)
- 2.5 Configure services (optional)
- 2.6 Enable services at windows boot (optional)
- 2.7 Install an X server (optional)
Installing a GNU userland
Enabling Windows Subsystem for Linux
To be able to run a GNU userland on windows, the Windows Subsystem for Linux (WSL) needs to be enabled. This can be achieved by opening Turn Windows features on and off from the Start menu and enable the Windows Subsystem for Linux feature.
This requires windows to be restarted in order to be able to continue.
Installing a GNU userland
To install a GNU userland open the Microsoft Store from the Start menu and type Linux into the search box. Click on show all and browse the available Linux distributions. Click on the desired (preferably free) distribution and click Get.
Note: this guide will use Debian GNU/Linux as its selected distribution. Other distributions may have different install procedures or package prerequisites in the following chapters.
Hint: it is not necessary to log into the store in order to download and install the selected distribution.
Setting up the GNU userland
Initial setup of the GNU userland
Open the Debian GNU/Linux app from the start menu and follow the instructions:
- wait for the initial installation to finish
- provide a username
- enter and confirm a password for the user
Setting up a root password (optional)
To be able to switch to the root user instead of using sudo a root password needs to be set. For this switch to the root user using sudo and set type passwd:
Note: this is a user propmt - these commands should be executed as an unprivileged user.
Note: this is a superuser propmt - these commands should be executed as the root user - this means that either sudo needs to be used in front of the command or the user must switch to the root user using su.
After the root password has been set up one can switch to the root user by simply typing su and providing the root password.
Unfortunately the sudoers package cannot be removed because it is necessary to start WSL services on Windows boot.
Update the system
Update the list of available packages:
List all upgradable packages:
Upgrade all upgradable packages:
Update the time and date settings
Install some useful tools (optional)
- screen: terminal multiplexer with VT100/ANSI terminal emulation
- mc: Midnight Commander - a powerful file manager
- dstat: versatile resource statistics tool
- openssh-server: secure shell (SSH) server, for secure access from remote machines
- bash-completion: programmable completion for the bash shell
- dos2unix: convert text file line endings between CRLF and LF
Configure services (optional)
Harden OpenSSH server configuration:
Add the following line at the end of the file (with your username instead of <USERNAME>):
Start the OpenSSH server:
Allow cron log:
Find the following line and uncomment it (remove the leading # character):
Save the file and exit the editor (<F2> => <y> => <Enter>).
Restart the system logger:
Start the job scheduler
Enable services at windows boot (optional)
In order to be able to start WSL services at Windows boot time, the desired service's init script need to be added to the sudoers configuration, so it can be started from Windows without the need to provide a password.
Note: background processes require windows build 1803 or later.
- screen-cleanup: cleans up stale sessions and initializes the session directory for the sessions
- rsyslog: system logger
- ssh: OpenSSH server
- cron: time-based job scheduler
Save the following as wls.reg and run it to add the registry keys to the current user's startup tasks:
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run] "wsl - cron"="debian -c \"sudo /etc/init.d/cron start\"" "wsl - screen-cleanup"="debian -c \"sudo /etc/init.d/screen-cleanup start\"" "wsl - rsyslog"="debian -c \"sudo /etc/init.d/rsyslog start\"" "wsl - ssh"="debian -c \"sudo /etc/init.d/ssh start\""
Install an X server (optional)
WSL can run graphical applications, but in order to be able to display them an X server needs to be installed on the windows system.
Available X servers are:
Download, install and start one of the above servers. Upon starting Xming or VcxSrv set the display number to 0.
Set the display in WSL:
Install a graphical application to test the X server: