Andrew Moore

Solutions Architect @ _nventive; Desktop, mobile and web developer; Tech enthusiast.

"RT @firefox: We strive to make Firefox a great experience. Last weekend we failed, and we’re sorry. More here, but one call out: if you en…"

Share


Archives


Categories


Experimenting with Windows Subsystem for Linux

WSL's introduction with the Windows 10 Anniversary update might just be the occasion you've been waiting for to get rid of that Cygwin shell.

Andrew MooreAndrew Moore

I’ve always preferred doing large batch processes in Linux. bash scripts are relatively easy to write and a myriad of CLI tools are at your disposal to get the job done. You have a thousand images to resize to various target sizes? A combination of find, convert from ImageMagick and a shell script will get it done in no time.

So, because of my preference for Linux’s CLI tools, I’ve always had some flavor of a Cygwin shell installed on Windows (lately, babun). However, Cygwin was always finicky: its path remapping can fail in specific situations, its internal memory allocation sometimes failed for no good reasons (leading to the famous “Couldn’t reserve space for cygwin’s heap” error) and the packages are usually outdated compared to the source Linux ones.

With the Windows 10 Anniversary update, Microsoft surprised a lot of people by shipping along the update the Windows Subsystem for Linux. WSL enables Windows 10 to natively run Linux executable within a POSIX-compatible environment. I therefore took the time to see if I could finally ditch that Cygwin installation I’ve been using all those years.

Installation

Installing WSL is relatively straight forward:

  1. Enable Developer mode by navigating in Settings > Update & Recovery > For developers and selecting the appropriate option in the list.
    wsl-enable-dev-features
  2. In the legacy control panel, navigate to Programs > Turn Windows features on or off. Check Windows Subsystem for Linux and hit OK.
  3. Reboot when prompted.
  4. In the start menu, find the entry for Bash on Ubuntu on Windows (that’s a mouth full).
  5. Confirm that you want to continue with the install by typing y when prompted.
  6. Setup your UNIX username and password when prompted.

Windows will download and extract a specially crafted distribution of Ubuntu (containing only the bare minimum to run a Linux CLI environment).

Customizing

By default, only your standard GNU utilities are installed. The image also comes with Ubuntu’s default of bash as a shell and nano as the default editor.

Changing the default editor is relatively trivial and you can do so the exact same way you would in a normal Linux distribution. Simply open your ~/.bashrc file and set your EDITOR environment variable as such:

export EDITOR='vim'

Changing the default shell, however, is a bit more complicated. Ubuntu on Windows‘s entry point, bash.exe, completely ignores what shell you have set in your /etc/passwd file. So once you’ve installed your desired shell thru apt-get, for example:

sudo apt-get install zsh

you have to modify your ~/.bashrc file to force bash to execute your alternative shell instead. You can do so by adding the following at the top of the file:

if [ -t 1 ]; then
    exec zsh
fi

Misc Findings

I’ve been using WSL for a couple of weeks and I have made a few miscellaneous findings.

Solutions Architect @ _nventive; Desktop, mobile and web developer; Tech enthusiast.