Published 2018-08-20.
Last modified 2024-10-25.
Time to read: 3 minutes.
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.
Configuration
This is my WSL configuration file, in my Windows home directory (%systemdrive%%homepath%\.wslconfig
).
See Advanced settings configuration in WSL for more information.
# 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:wsl2.autoMemoryReclaim=drop
wsl.exe --update --pre-release
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.
Display whether you have WSL1 or WSL2 by typing wsl --list --verbose
into a PowerShell prompt, like this:
PS C:\Users\mslin>wsl --list --verbose NAME STATE VERSION * Ubuntu Running 1
The above shows that a machine has WSL1 installed.
Ignore this step if you have WSL2.
The default Ubuntu sleep
command does not work on WSL1.
sleep
must work properly in order for the upgrade to succeed.
To fix the problem, replace /bin/sleep
with an equivalent Python 3 program prior to running do-release-upgrade
.
This will avoid the problem sleep: cannot read realtime clock: Invalid argument
described in
this askubuntu posting.
To do this, type:
$ sudo mv /bin/sleep{,-} # renames sleep to sleep-
$ sudo vi /bin/sleep # I use vi, but you can use any editor with sudo
Enter the code for /bin/sleep
shown below using your favorite editor:
#!/usr/bin/env python3 import sys import time time.sleep(int(sys.argv[1]))
Save the file.
Now make your replacement for sleep
executable:
$ sudo chmod a+x /bin/sleep
Ensure that all previous upgrades have been applied:
$ sudo apt upgrade
Verify that the last line of /etc/update-manager/release-upgrades
is Prompt=normal
.
If not, edit with your favorite editor:
$ sudo vi /etc/update-manager/release-upgrades
Run the upgrade.
Because Ubuntu rolls out its upgrade to users gradually, you might have to try this several times over a few days.
Some of my machines update earlier than others, even though they are in the same building.
You may find instructions elsewhere that advocate "Force direct upgrade by using the -d switch".
This is incorrect.
There is no such thing as a direct upgrade, instead the -d
switch installs a development version,
which means you will forever after install a whole lot of prerelease software.
Don't do that unless you have a good reason.
This is what most users should type:
$ sudo do-release-upgrade
The installation will die after a while with the following error:
dpkg: error processing package libc6:amd64 (--configure):
installed libc6:amd64 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
libc6:amd64
To fix the problem
(from https://stackoverflow.com/a/61697214/553865
),
edit /var/
and comment out this line near the top of the file:
set -e
so it looks like this:
# set -e
Now type:
$ sudo apt -f install
To conclude the upgrade, type:
$ sudo apt upgrade --fix-missing $ sudo apt upgrade $ sudo apt-get dist-upgrade -y $ sudo apt autoremove $ sudo apt autoclean
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:
$ cmd.exe /C start my_file.mkv
I defined a bash alias to make this easier:
alias run='cmd.exe /C start'
Reload the bash aliases after editing ~/.bash_aliases
:
$ source ~/.bash_aliases
Now use the run
alias to run the default Windows video viewer for .mkv
files like this:
$ run my_file.mkv