Windows Subsystem for Linux (WSL)

Windows Subsystem for Linux Revisited

Published 2018-08-20. Last modified 2024-06-06.
Time to read: 2 minutes.

This page is part of the posts collection, categorized under Git, Ubuntu, WSL.

I’ve been using Windows Subsystem for Linux (WSL) headless since it was first released with Windows 10 version 1607 in August 2016. The April 2018 release of Windows 10 (version 1803) significantly improved WSL.

It is possible to work with Ubuntu graphically on a vanilla Windows machine. No special drivers are required. No special Linux or Ubuntu support is required from the computer vendor.

This is my setup for running an X client like xeyes or IntelliJ IDEA from WSL or WSL2, accessed via a Windows X server like VcXsrv. These scripts assume Ubuntu 18.04 was installed under WSL.

Desktop showing Windows Subsystem for Linux (WSL)

Essential Scripts

Here are bash scripts to install everything:

Optional Scripts

The remaining scripts are all optional.

VNC

These bash scripts allow VNC to connect to a remote machine or to WSL on the local machine.

Packages and Programming Environments

Installation of various packages and programming environments follow.

Git

Python

NodeJS

Java Virtual Machine

Miscellaneous

Wine

The advent of WSL means that Wine is no longer required!

Configuration

This is my WSL configuration file, in my Windows home directory (%systemdrive%%homepath%\.wslconfig). See Advanced settings configuration in WSL for more information.

%systemdrive%%homepath%\.wslconfig
# See https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig
# See https://github.com/microsoft/WSL/issues/4166
[wsl2]
memory=8GB
swap=60GB
#processor=4
localhostForwarding=true

[experimental]
autoMemoryReclaim=drop
sparseVhd=true

2024-02-20 Update

The WSL v2.1.3 prerelease sets the the default memory reclamation mode to dropcache. The following is now a default setting:
%systemdrive%%homepath%\.wslconfig
wsl2.autoMemoryReclaim=drop
The memory will be freed using dropcache after 10 minutes of inactivity. To upgrade WSL using bash, cmd or powershell:
bash, cmd or powershell
wsl.exe --update --pre-release
Wait a few minutes before restarting a terminal session. It is not necessary to reboot after upgrading.

Upgrading from Ubuntu 19.11 to Ubuntu 20.04

Update Aug 17, 2020: Here are my notes on upgrading WSL and WSL2 from Ubuntu 19.11 to Ubuntu 20.04.

Run Associated Windows Program

To run the Windows program associated with a file, preface the file with cmd.exe /C start.

For example, to run the default Windows video viewer for .mkv files, type:

Shell
$ cmd.exe /C start my_file.mkv

I defined a bash alias to make this easier:

~/.bash_aliases
alias run='cmd.exe /C start'

Reload the bash aliases after editing ~/.bash_aliases:

Shell
$ source ~/.bash_aliases

Now use the run alias to run the default Windows video viewer for .mkv files like this:

Shell
$ run my_file.mkv
* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.