RSS

Windows Subsystem for Linux

11 May

Episode 69

Last five weeks we focused on Amazon Web Services, let’s have a short break from that. Recently I’m working in a project where majority people works on Mac (why… ) or Linux (why… ) while I’m definitely a Windows user due of numerous reasons I’m not going elaborate on in this article. Honestly I’m still startled, since I was never in an environment where more than 10% of developers used anything else than Windows on their work stations (I’m not talking servers), and I was in quite a few environments. Anyway, unfortunately, OS agnosticism is a distant value to some people, so I was often finding myself in a situation where I need to either convert stuff to be OS independent or to run on Windows. At some point I grew tired of that and looked for a ways to run Linux shell scripts on my machine.

penguin_by_forrestimel-d5htxg3.png

There are quite a few, and one of them will be our topic today. Windows Subsystem for Linux, also known as WSL, Bash on Ubuntu on Windows, or just Bash on Windows gives us the Ubuntu shell build into Windows 10. You can run Linux commands, download and install programs and access files on Windows partitions. It’s still an experimental feature, but works very well for my needs.

There is a Penguin on my Window!

It’s not a virtual machine, it’s not a Docker container, It’s not a library nor an emulator. It’s a new kernel layer, more or less, based on Microsoft’s Astoria Project that was meant for running Android apps on Windows. The concept is a bit similar to Wine on Linux, but the other way around. Wine lets us run Windows applications on Linux, WSL lets us run Linux application on Windows. WSL was mostly intended for developers who would like to run Linux command line tools and have a human-friendly system at the same time (and maybe play a game after work, or write a blog article in a decent document editor).

My use cases were simple – I had to write and test a bash script. I could do that on remote Linux machine, but it was a bit inconvenient for me. I needed to do a bit of logic, download some files, transform them with jq, and upload to Google Storage. I could use apt-get to fetch and install whatever I needed and it worked. I could edit scripts in Notepad++ or some IDE, under Windows and run it under WSL bash like a charm. Just need to remember about end of line encoding in files. Windows partitions are available under /mnt/c/ , /mnt/d/ etc.

How do I get it?

WSL is available for 64 bit version of Windows 10, starting with Anniversary Update build 14393. Let’s quickly go through steps:

  • You need to turn on Developer Mode. It can be done in Settings -> Update and Security -> For developers menu. Choose Developers mode radio button.
  • To enable WSL, go to Windows Features tool (search for “Turn Windows features on off”). Select “Windows Subsystem for Linux (Beta). The other way to do that is to open PowerShell as administrator and run: “Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • Restart if prompted.
  • Open a command line and run “bash“, accept the license.
  • WSL will be downloaded and installed. You can start by running “bash” in command line or via shortcut.
  • First time you run it, you will be prompted to create Unix user with password.

That’s it, no big deal. You can refer to the installation guide on Microsoft’s page if you get lost.

425234-Kycb.jpg

What are the alternatives?

As I’ve mentioned, there are quite a few ways you can deal with Linux specific stuff while being a Windows user.

  • You can login to an external Linux machine via SSH and do your stuff there. It might be feasible for simple needs, but inconvenient in the long run. Also, you are dependent on network and another machine.
  • You can install second system. That is probably the most complete solution for potential compatibility problems, but you can be on one system at the time and switching back and forth will be tedious to say the least.
  • You can start a virtual machine with Linux. That will mitigate the switching problem, but also requires a lot of resources.
  • Similarly, you can run a Linux container in Docker. This will however require some effort to persist your work and probably not give a lot of advantage over virtual machine.
  • You can get Cygwin – a Unix-like environment and command line for Windows. But you can’t run an unmodified Linux software on it. To quote hackday.com article on WSL introduction:  “Cygwin can suck it”.

In recent years, Microsoft seemingly stopped to combat Linux and decided to cooperate, which is probably for the benefit of everyone. Windows Subsystem for Linux looks good, even though it’s still in beta, and I would recommend it as a useful tool in developers work, assuming that you work on software that will finally run on Linux servers (which is basically any software, providing you are a part of Java world). Go ahead, give it a try, the penguin won’t bite. And if it would, you can always just click this familiar x in the top right corner of WSL bash window and carry on. Happy bashing and see you next time.

how-to-train.jpg

Image sources:

 
Leave a comment

Posted by on May 11, 2017 in Misc, Technology

 

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: