Application Report: Development with Windows Subsystem for Linux

The Windows Subsystem for Linux enables the execution of Linux commands in the command line in Windows 10.

Since autumn 2017, the Windows Subsystem for Linux (WSL) is finalized and not in the beta phase anymore. It has been firstly announced in 2016. In this article, Inpsyder Daniel Hüsken gives a short introduction into WSL and explains how to use the WSL and what kind of benefits the Windows Subsystem for Linux offers to developers.

What can Windows Subsystem for Linux (WSL) do?

The Windows Subsystem for Linux allows developers to execute a Linux environment on a Windows System directly (most command line tools and applications included) without the overhead of a Virtual Machine.

In its documentation it says:

  1. Choose your favorite Linux distributions from the Windows Store.
  2. Run common command-line utilities such as grep, sed, awk, etc.
  3. Run Bash shell scripts and Linux command-line applications including:
    • Tools: vim, emacs, tmux
    • Languages: Javascript/node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, etc.
    • Services: sshd, MySQL, Apache, lighttpd
  4. Install additional Linux tools using the distribution’s built in package manager (apt-get, for example).
  5. Invoke Windows applications from the Linux console.
  6. Invoke Linux applications on Windows.

In order to use the WSL, you need Windows 10 with the Fall Creators Update (Version 1709). That’s because the WSL was published in the final version, so the Linux distributions are available in the Microsoft Store. In older Windows 10 versions, WSL is still in beta status and only available with Ubuntu.

Although most applications work with WSL, there are still a few which won’t. This is Docker for example. Two reasons are possible. Either these applications execute system calls in Linux which are not implemented yet or they need a grafical interface.

How to install WSL

The installation of WSL is quite easy. Here’s a short instruction.

First you need to activate the feature:

  • Right-hand click to the Windows start button, then choose “apps and features”
  • Search in “search setting“ for “Windows features” and open it
  • Scroll to “Windows Subsystem for Linux” and check it. Click OK
  • Reboot

The next step is to install the Linux Distribution from Microsoft Store:

  • Open Microsoft Store
  • Search for the desired distribution (I chose Ubuntu)
  • Click “install”
  • Start Ubuntu/the distribution you chose (The rest of the installation is going to be executed.)
  • Then you are asked to create a UNIX user name and a password (You need the password for the “sudo” access)

Great job! You finished the installation.

Now you can start the WSL via the Ubuntu Icon or when entering “bash.exe”.

How I work with the Windows Subsystem for Linux

As the WSL hasn’t installed much innately, simply install packages with “sudo apt-get”. I created a provisioning script for that, which installs some tools like GIT and PHP and creates links so that GIT operates per SSH. I just let it run now.

You can reset the whole WSL quite easily. Simply use the command “lxrun /unisnatll /full” in the normal command line interface while being in the administrator mode. Then uninstall the Ubuntu app.

You can find the Window’s file system in WSL in “/mnt/<DriveLetter>/”.

If you want to work with PHPStorm and the WSL, you need to install many tools in Windows and the WSL at the moment. However, JetBrains plans to offer WSL Support. Once this is done, you only need to install GIT in the WSL. But in case you only work with the command line, there shouldn’t be a problem.

Nevertheless you can already integrate PHPStorm as terminal in the WSL.

Simply search for “terminal” in the settings and add  “C:WindowsSystem32bash.exe” in “Shell path”.

Note: When developing, always remember not to work with absolute paths. As it may happen that you use PHP in Windows or the WSL, you should always use the constant __DIR__.

You can also start Windows programs in the Shell. To do so, simply execute the .exe file. On the other way round, you can also call Linux commands in Windows. However, to do so, you need to use the “bash.exe -c “ls””. The WSL translates the paths automatically or you have to indicate them with /mnt/… .

Docker runs in my WSL, too. If you also want that, you need to do these things: Install Docker in Windows and the WSL. Then tell Docker in WSL that it shall use Docker in Windows. Now you can at least use the commands.

My Conclusion: Advantages for Development

Using the Windows Subsystem for Linux in web development offers the huge benefit that I can execute Linux scripts which wouldn’t work in Windows otherwise. Moreover I stay in a familiar environment as the most web servers run on Linux. Additionally, you can use all these wonderful Linux commands in Windows.

I almost always use the WSL in Windows when I use a Shell.

With this tool Microsoft created, you don’t need to think about changing an operating system, in my point of view. WSL offers everything I need.

You have another opinion? Or you have questions? Simply leave a comment below, I’d be happy to get in touch with you.