6 minutes
Bash on Ubuntu on Windows
August 5, 2016
What is it
In a nutshell Bash On Ubuntu On Windows (got to love that name) is the combination of Microsoft’s new Linux Subsystem with the user mode pieces from ubuntu.
Yes you read that right Microsoft and Canonical (the guys who make Ubuntu) are working together on this. What this lets you do is fire up a bash environment along with all the package deployment tools you would expect from ubuntu like apt-get etc.
Haven’t we had this kind of support on Windows before?
In the past there has been tools that let you run Unix like environments on Windows.
Cygwin
Cygwin was a Linux like environment that emulated Linux/Unix on top of Win32. It has a lot of performance issues due to the emulation.
The main use for this environment was to compile Linux/Unix executables into Win32 executables. It did this ok but I wouldn’t want to use this as a day to day environment.
Unix Subsystem
Microsoft had a Unix subsystem with the goal of letting people run Unix applications on windows. It didn’t really take off and as a result Microsoft didnt’ really maintain it. It basically became it’s own outdated version of Unix.
Various Executable versions of Unix tools
This to some extent has been successful way to run Linux/Unix tools. Git is a perfect example. I still see this being done even with this new bash environment.
Bash On Ubuntu On Windows
This environment is better than previous efforts for the simple reason that while it is a subsystem like Unix Subsystem was it’s user mode binaries are maintained by Canonical. This means Microsoft will target the support to run said binaries and Canonical will keep it in line with their Long Term Support branches of Ubuntu.
Who is this actually target at?
This tool is primarily targeted at developers. There is a large group of developers who are now buying Macs so they can run things in bash which is similar enough to the environment running on their production Linux servers.
I would argue this will give a better user experience than using a mac because Ubuntu user mode packages will be even closer than the bash environment on the mac.
Also if you trash your Linux environment you can reset it.
Does this mean Microsoft are going to abandon Powershell now?
No, have you ever tried doing administration on Windows with just updating text files? Yeah it isn’t going to go to smoothly. There is a massive difference between how Unix systems and Windows system are managed.
Unix type operating systems likes to treat everything as a file and all configuration is done via making changes to text files. As a result Unix admin tools are great at modifying text.
Windows on the other hand is very API driven. To make changes to a windows system you need to make lots of calls to Com components, change registry keys or make WMI calls. Also Microsoft now has the creation of Powershell cmdlets as part of their engineering standards for new and updated products.
There is also speculation that with Powershell now running on .NET Core it might be ported to Linux.
How to install
-
First thing you need to do is make sure you have the Windows 10 anniversary Update installed.
-
Once that is installed you can run the following command to complete the install:
Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Windows-Subsystem-Linux
-
At this point you will need to restart your computer.
-
Next run the following command to do the install.
lxrun /install /y
- Now you can start Bash from the start menu or run bash.exe from Powershell or Cmd.
Reset Linux Environment
If you break your Linux environment and want to reset it back to default you can do so with the following commands:
To uninstall:
lxrun /uninstall /full /y
To reinstall:
lxrun /install /y
Linux file location
The Linux install is stored in your profile “%localappdata%\lxss”. This folder is hidden with the system attribute so you won’t be able to see it in explorer with default options.
Note: Don’t delete this folder to clean it up. Use the lxrun command listed above instead.
Updates
You can update the environment by calling the following command:
lxrun /update
This appears to just call apt-get to do upgrades. You can do it either way.
Limitations
Currently there are a lot of limitations with this and it currently is still marked as Beta.
STDIO Streams
You can’t send data into the stdin or receive data from stdout with Linux to Windows process. If you run bash in a console window you will see the text but as soon as you try to capture it, you will start to see errors.
This appears to be a limitation of the Win32 Subsystem interacting with the Linux Subsystem.
The workaround for this is to use text files. You can create a text file and have bash read it and vise versa.
You can pass commands into bash with the -c option.
bash -c "ls >/mnt/c/temp/myoutput.txt"
bash -c "cat /mnt/c/temp/myinput.txt|mylinuxcommand"
Execute Windows commands
Currently you can’t launch Win32 executables from in the Bash environment. There is a high rated issue raised on their user voice page.
X Windows
There currently is no support for x windows at all. This is to be expected because implementing that would take a lot of work.
Hopefully it is added in the future but I wouldn’t expect it to be very high on the priority list.
Kernel
As expected anything requiring a kernel module to be loaded or the like won’t work. Microsoft has mentioned they don’t expect to open source the kernel component and even if they did you wouldn’t be able to compile it due to signing requirements.
If you need to use the Linux kernel I would recommend using a Virtual Machine instead.
Background processes
You can’t run any background processes like daemons, screen sessions or even cron jobs. As soon as you close bash it will terminate all Linux processes.
No Java
One thing I have seen a lot of people complain about is the lack of Java support.
This hopefully is something that is resolved soon. If this is of interest to you I would recommend following the user voice page.
Can’t be run on a server versions of Windows
This Linux subsystem is only supported on the client version of Windows 10 (no Windows 2016 support). This is primarily because the tool is designed to give developers an environment to work on. If you want to run Linux applications on a server you will have a better experience running a Virtual Machine instead.