The Windows Subsystem for Linux From Web Developer Perspective

The Windows Subsystem for Linux From Web Developer Perspective

If a Web developer would make a switch to Windows from Linux or MacOS, the most significant thing they would miss is a proper Unix shell. Disclaimer: that statement is only based on discussions with numerous web developers, so the sample size rather small. Windows users have been using non-Unix commands (PowerShell) or emulated the Unix tools (Cygwin) which can lead to troubleshooting an issue that the rest of the team using MacOS or Linux hasn't encountered. Windows Subsystem for Linux (WSL) can bring a change to this situation. In this blog post, I'll explain why I switched to using Ubuntu bash instead of alternatives, and share the positive and negative experiences I have had when using it.

Why Windows Subsystem for Linux?

Windows users have always had multiple choices for command line tasks, such as PowerShell, Command Prompt, Cygwin, etc. Each of them has their issues.

Windows Shell Options - Cygwin, PowerShell, Command Prompt

The PowerShell is a powerful command-line shell and scripting language but only used on Windows machines. As a side note, PowerShell Core can be run as a cross-platform tool. From web developer perspective PowerShell is not widely used in the JavaScript build scripts or tools.

The classic Command Prompt is always at your disposal on the Windows machine. Unfortunately, Command Prompt feels abandoned, and overall experience is just sad, to put it mildly.

Cygwin takes a different approach as it tries, as the project description says, "Get that Linux feeling - on Windows". You can use many of the Unix tools, and Cygwin.dll provides POSIX compatibility. Cygwin doesn't mean that you can run Unix binaries, all libraries and tools need to be compiled from the source.

There are excellent pre-configured Cygwin's such as Babun.

Windows Subsystem for Linux takes a different approach.

The Windows Subsystem for Linux (WSL) is a new Windows 10 feature that enables you to run native Linux command-line tools directly on Windows, alongside your traditional Windows desktop and modern store apps. --WSL FAQ on Microsoft website

It is a bit difficult to find information what WSL is, but this the definition I came up after reading many FAQs.

The WSL is a compatibility layer for running Linux applications. By default, WSL includes a Bash, and therefore you're ready to use commands like awk, grep, etc. Linux distribution you can install from Windows Store.

When you use Windows Subsystem for Linux, you can access your code from the Windows file system. For example, C:\GitHub\YourProject.

You can read more on WSL from Microsoft's FAQ.

The Good

The WSL is light on resources as it isn't a virtual machine based solution.

The setup is easy as you can now install the Linux distribution, such as Ubuntu, from the Windows Store.

The WSL is not an emulation of tools, so everything works as expected because the tools are real Unix commands and not Windows applications that try to imitate the original ones.

Especially for the Web developers who use Node.js based tools, WSL brings very stable native packages as the Linux compilation of the packages is way more tested than the Windows counterpart. The installation of the Windows build tools has gone easier, thanks to Windows build tools package. Still, the Linux compilation is in my experience is easier and more reliable due to the larger user base. Installing build tools is easy: sudo apt-get install build-essential.

A big plus is also access to rock-solid package manager (for example, apt-get) and a vast amount of packages.

Access to same files with the Windows file system without mounting and sharing drives.

Finally, equivalent dev environment with the whole team. You're not anymore the only person on the team who is seeing Windows-specific issues and no one able to help you with the problem because they can't reproduce it.

The Bad and The Ugly

Based on the previous section, one might think we're living on a perfect planet. Almost. There are two kinds of instability issues that I have encountered.

First, random file system errors when doing heavy I/O operations, in Web development that is, of course, npm install.

I use Windows Bash on Ubuntu on a daily basis and everything has gone smoothly except on some operations I get random file system errors. Operations such as running tests using jest or installing npm packages with yarn. Any ideas? pic.twitter.com/pZFSqK8jmE— Tatu Tamminen (@_Tx3) January 12, 2018

Embedded JavaScript

I have tested on two different machines, with same results, a random file access errors. The first run gives an error on file X, the second run error on file Y and the third run everything is fine.

The same thing happens with JavaScript unit tests.

Another issue I have encountered is that the Windows subsystem doesn't find Linux distribution at all. I just get a blank terminal, and nothing happens. Missing distribution errors occur rarely, but when it does the only thing that has remedied the situation is a classic solution, reboot.

A non-technical problem, sometimes it is hard to remember that if you're doing npm install on the WSL-side then the binaries are in Linux format. If you accidentally try to start your project on, for example, PowerShell then it won't work without deleting node_modules folder and doing npm install again.

Conclusion

Even with these issues, I have been super-happy running Linux environment on my Visual Studio Code setup. Microsoft has made installation I think it is a matter of time that the stability issues are solved. It's hard to tell if I am the only one encountering these issues.

One thing I am looking forward to doing some customizations, starting with fonts and colors. I think the next step after that could be learning to use tmux.

Discuss on Hacker News