Often developers and related OPs need to test stuff on Linux (web, cli, .NET Core etc.). The typical approach was to spin up a Virtual machine (VM), install and configure a Linux distro and play with it.
Main Cons include: you need a hyper-visor software, enough RAM, fast hard drive, to fight with basic operations like cope-paste text and files between machines etc.
Well, good news! As of the Anniversary Update Windows 10 supports the so called “Windows Subsystem for Linux” (WSL). It allows you to run natively* most of the non GUI Linux stuff**on Windows without the overhead of a virtual machine.
When you start Bash it will appear within standard Windows console window (since it is hosted by ConHost.exe). Therefore you can benefit from both Bash’s colors and beauty and Windows’ console window transparency, fonts and settings:
* WSL is a result of many years of work and combines different projects (like Drawbridge) together with some User/Kernel support.
In fact Linux apps run in a sandbox and all api/system calls are translated in a way that Windows will understand. This is kind of application virtualization.
Of course it comes with some limitations since no real Linux Kernel is running on the Windows box. But it’s fairly enough for day-to-day dev & test tasks.
It’s worth to say that running Linux on Windows i primarily intended for dev & test and not for running heavy websites & databases in production since Shell’s virtualization comes with performance costs.
I’d also recommend you to watch Scott Hanselman’s intro to Bash on Ubuntu on Windows. He is explaining a lot!
So let’s install Linux on our Windows 10 box.
HIGH LEVEL STEPS
- Enable WSL support
- Choose and install a Linux distro from Windows Store
- Configure your Linux distro
WSL evolved through the last few Windows 10 updates and betas as well as the installation/configuration steps. This guide applies to Windows 10 1709. Also we will install Ubuntu.
- Install WSL
- Via PowerShell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Via Control Panel:
- Open “Windows Features”: Control Panel > Programs > Turn Windows features on or off
- At the bottom of the list select “Windows Subsystem for Linux” and click Ok:
- Via PowerShell:
- When prompted restart your computer
- Install Linux distribution (two ways to do it):
- In the Start menu search for Bash and start it. You will be provided a hyperlink. Open it in the Browser. This will start Windows Store from where you can pick a distro. Click and install Ubuntu.
- Open Windows Store and search for Ubuntu. Click on the icon and install it.
- Wait for the installation to complete
- In the Start Menu search for Ubuntu or use the desktop shortcut.
- The first time you will be asked for a username and a password
You can now check all mountpoints using
It’s worth saying:
- The installation is per user, not system wide
- The rootfs partition is located at
Now let’s have some Linux fun on our Windows box:
1) Force ipv4 to avoid apt-get delays:
echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4
2) Update our Linux distro:
sudo apt-get update sudo apt-get upgrade
3) Install mc (Midnight Commander)
sudo apt-get install mc
4) Install Apache2
sudo apt-get install apache2
4.1) Modify default ports to avoid collisions with IIS/Skype
4.2) Restart Apache
sudo /etc/init.d/apache2 restart
4.3) Test Apache on your Windows box
Uninstallation of this cool feature is also supported. Remember that Bash Shell comprises of two components: WSL & actual Linux distro (Ubuntu in this case). So the removal is two stage process:
1. Removing Ubuntu component. You have two options:
1.1. Using lxrun incommand-prompt:
lxrun /uninstall full /y
1.2. Using Apps & Features in Settings (available as of “Fall Creators Update”):
2. Remove WSL.
2.1. Using PowerShell:
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
2.2. Using Windows Features dialog in the Control Panel:
In both cases after removing WSL, you have to restart your computer.
REPAIRING / RESETTING / TERMINATING
In case something had gone wrong with the installation, there’s an option to repair / reset it. Find your distro in Apps & Features, click on the row and choose Advanced options:
Then choose your action:
Keep in mind that Reset will remove rootfs folder completely. It will be recreated after the first run of Bash shell.
- Making Ubuntu on Windows a bit more Authentic
- Windows 10’s Bash shell can run graphical Linux applications with this trick