Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / operating-systems / Linux

Linux (Bash Shell) on Windows 10 – My Experiments

5.00/5 (2 votes)
28 Nov 2016CPOL5 min read 12.2K  
Linux (Bash Shell) on Windows 10

A few days ago, I needed to rebuild my primary box to use the space more efficiently. Over time, the previous disk-plan had proved wrong with some drives being used up close to capacity and others lying eerily vacant. With that decision came the million buck question “What OS?” I wanted to try out the new Windows Server 2016. Though its latest-available download is only an RC, it has already RTMed (and the last RC is 99.999% the RTM bits) with the RTM key becoming available mid-October.

However, things rarely go to plan and the PC was beset with BSoD problems right from the start. With just the OS installed, the system crashed to a blue screen some 16 times. Finally, I gave up in frustration. A friend of mine berated me on Twitter on not using Windows 10 though it was perfect for what I wanted to do, was the next gen OS that I should be on, etc.. My last outing with Windows 10 was not so pretty (detailed here in my original review and here again when I listed out my misgivings with it).

Anyways, I went ahead and installed the Pro edition. Surprise, surprise! Most of my earlier misgivings had been taken care of (except my lament about OneDrive and OneNote — which still cannot be uninstalled !!!). So I was happy. I set up the system quickly for Hyper V and Containers. Then it took almost half a day more to catch up on Windows Updates. From there, I set up the other software I need.

This post is really about the Windows Subsystem for Linux (WSL). What it means is the opposite of that title — you’ll be running Linux inside of Windows 10 and not the other way around. Getting to this is a little tricky, but easy enough.

Getting WSL on Windows 10

Pre-requisite: You must have the Windows 10 Anniversary Update. This shows up as “Feature update for Windows 10, version 1607” in the updates list. Without this, the required features will not appear.

Tap the START icon, type “Developer features”. You will be taken straight to the “Use developer features” applet. Here, ensure “Developer mode” is checked.

Enable using Developer mode features on Windows 10

Now, open the “Turn Windows Features on or off” applet (START > type “Turn windows features…”). Scroll right down to the bottom of the list and find “Windows Subsystem for Linux (Beta)”. Yes it is STILL in beta.

Windows Subsystem for Linux on Windows 10

Click OK and wait. It should not take more than a couple of minutes. When done, reboot the system. It may restart a few times, wait patiently.

After it boots up, tap on START and you should find “Bash on Ubuntu on Windows” listed. You can either launch this, or from a standard Command Prompt or PowerShell, run “bash”. Here is how they would look:

Bash on Ubuntu on Windows (WSL) launched from Windows Command Prompt

Bash on Ubuntu on Windows (WSL) launched from Windows Command Prompt

Bash on Ubuntu on Windows (WSL) launched from direct shortcut

Bash on Ubuntu on Windows (WSL) launched from direct shortcut

Bash on Ubuntu on Windows (WSL) launched from Windows PowerShell

Bash on Ubuntu on Windows (WSL) launched from Windows PowerShell

This is an almost full blown copy of Ubuntu. You can install and run almost anything in it.

Note: A few things will not work correctly in WSL. For example, if you install any daemons (services) in the Linux, they are created as native processes in Windows (you can see it in Task Manager). You may receive many different kind of errors, some of which can be safely ignored.

See this screenshot of trying to start and query the MySQL daemon in WSL:

Starting MySQL service in WSL results in a few error messages and core dumps. These may be safely ignored.

Starting MySQL service in WSL results in a few error messages and core dumps. These may be safely ignored.

You can see some WSL processes in Windows 10 Task Manager. Here, you can see the MySQL daemon I had started in the Bash shell. Note that it shows up without a description. The "mysqld.exe" is an instance of MySQL Service running natively on my Windows 10 host (as a Windows Service)..

You can see some WSL processes in Windows 10 Task Manager. Here, you can see the MySQL daemon I had started in the Bash shell. Note that it shows up without a description. The “mysqld.exe” is an instance of MySQL Service running natively on my Windows 10 host (as a Windows Service).

And here’s me running MySQL Workbench from within WSL:

MySQL Workbench installed within WSL using apt-get. Then you need Xming on your Windows 10 host, and "export DISPLAY=:0" in your .bashrc file. Then simply launch the app!

MySQL Workbench installed within WSL using apt-get. Then you need Xming on your Windows 10 host, and “export DISPLAY=:0” in your .bashrc file. Then simply launch the app!

Some Gotchas

After playing with WSL for a while, I thought to myself, I can use this without needing to run a different host or VM for Linux. Since I can readily install anything I need (MySQL, Apache, PHP, dev stuff, etc.) right in here! However, I found to my disappointment that the shell is exactly that... you close the Bash session and it takes all the apps and everything you were running with it.

The data you save into WSL (files you create, apps you install, configuration you change) are preserved though. Therefore, you can use it for all that stuff I said earlier, only you must remember to fire up the Bash shell every time and ensure the required services/daemons are started.

Visual Studio Code

I tried to install Visual Studio Code. However, it seems to have a strong dependency on the Gnome shell?? It installed fine, then dpkg noted some dependency issues. I fixed those using “dpkg -f install” and all those packages were installed as well. Then when I tried to launch code, I got an error message that “libgconf-2” was missing. I installed that as well.

Now what happens is that the prompt just returns. No window pops up, no error message written to console, nothing. Just silence.

I have filed an issue on GitHub to track this: https://github.com/Microsoft/vscode/issues/13138.

I’ll post updates on my further experiments in future posts here! Keep watching.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)