Since the Win­dows 10 Fall Cre­ators Up­date from 2017, the Win­dows Sub­sys­tem for Linux (WSL) is a fully sup­ported Win­dows fea­ture. In case you don’t al­ready know about that fea­ture: WSL is a com­pat­i­bil­ity layer which al­lows run­ning 64 bit Linux bi­nary ex­e­cuta­bles (in ELF for­mat) na­tively on Win­dows 10 and Win­dows Server 2019 in a con­sole win­dow. It uses much fewer re­sources than a fully vir­tu­al­ized ma­chine. Since all Win­dows dri­ves are, by de­fault, mounted with their drive let­ters under /mnt/ it also al­lows users to use Win­dows apps and Linux tools on the same set of files. By press­ing Shift while right-​clicking on a di­rec­tory in the ex­plorer, you will even see a new con­text menu entry named “Open Linux shell here“.

To en­able WSL you need to en­able the cor­re­spond­ing Win­dows Fea­ture: press WIN+R, enter “op­tion­alfea­tures“, press Enter, en­able the “Win­dows Sub­sys­tem for Linux” in the di­a­log and re­boot the ma­chine. After that, you can choose from and in­stall one of the Linux dis­tri­b­u­tions avail­able in the Mi­crosoft Store: UbuntuUbuntu 18.04 LTS, De­bian, SUSE Linux En­ter­prise Server 12open­SUSE Leap 42Kali Linux, or just search for “Linux” on the Mi­crosoft Store. At first start, you have to choose a user­name and a pass­word and you are good to go. You can read more about the in­stal­la­tion process in this Mi­crosoft Guide.

Going be­yond

Mi­crosoft sees the Win­dows Sub­sys­tem for Linux pri­mar­ily as a tool for de­vel­op­ers, es­pe­cially web de­vel­op­ers. For ex­am­ple, the gcc com­piler and the build-essential pack­age is in­stalled by de­fault. Let’s see, if we can go be­yond that stated pur­pose and run Linux GUI ap­pli­ca­tions on Win­dows with­out the over­head of a vir­tual ma­chine. And in­deed that’s pos­si­ble.

The first step is to in­stall an X Server. There are al­ready a lot of X Server apps for win­dows you can choose from. Maybe the most pop­u­lar and up-​to-date soft­ware is the VcXsrv Win­dows X Server. Un­for­tu­nately, that didn’t work. Next, I tried the Xming X Server for Win­dows, and even though the free ver­sion of this soft­ware hasn’t been up­dated for al­most three years, it worked per­fectly.

After in­stal­la­tion of an X Server, we have to tell the Linux apps where to send the video data. To make that in­for­ma­tion per­sis­tent, you can cre­ate or edit the file .bash_profile in your home di­rec­tory

sudo nano ~/.bash_profile

and add the line

export DISPLAY=:0

Next, we can in­stall Fire­fox the usual way. For this test, I have in­stalled De­bian 9.7 as the WSL dis­tri­b­u­tion, so the stan­dard pack­ages pro­vide Fire­fox ESR:

sudo apt update
sudo apt install firefox-esr
firefox

If all worked well and the X Server is run­ning, the Fire­fox app win­dow should now open on your Win­dows desk­top.

There is one caveat: there is no graph­ics ac­cel­er­a­tion avail­able, so the video out­put might be a bit slow some­times.

Small ex­cur­sion: Se­cur­ing the en­vi­ron­ment

After the in­stal­la­tion of Fire­fox, one might have the idea to use the Win­dows Sub­sys­tem for Linux as a se­cure brows­ing en­vi­ron­ment to guard Win­dows against the di­verse dan­gers of the web. But as men­tioned above, all local dri­ves are mounted by de­fault in the sys­tem and every Linux process can, by de­fault, read from and write to that dri­ves. To change that, the Win­dows Sub­sys­tem for Linux in­tro­duces the con­fig­u­ra­tion file /etc/wsl.conf. The con­tent of this file is for­mat­ted ac­cord­ing to any Win­dows ini file: a text file with sec­tion names in square brack­ets, fol­lowed by key-​value-pairs. This is an ex­am­ple con­fig­u­ra­tion file with, at the time of the writ­ing of this post,  all pos­si­ble keys set to their de­fault value:

[automount]
enabled = true
root = "/mnt/"
options = ""
mountFsTab = true
[network]
generateHosts = true
generateResolvConf = true
[interop]
enabled = true
appendWindowsPath = true

The most rad­i­cal way to se­cure the en­vi­ron­ment would be to set the key enabled to false in sec­tion automount. No dri­ves are mounted any more and no mal­ware can change data out­side of the vir­tual file sys­tem. But that also means that you can­not ac­cess any data on your win­dows dri­ves to, for ex­am­ple, up­load files.

To allow at least read ac­cess to the dri­ves, you can set the options key in sec­tion automount to the value metadata,umask=222,fmask=222.

An­other at­tack vec­tor from in­side the WSL would be to start a win­dows pro­gram to change data, as any win­dows process can ac­cess the Win­dows dri­ves and also runs with the ac­cess rights of the user start­ing the WSL com­mand shell. To change this, just set the key enabled to false in sec­tion interop. This way, no Win­dows pro­gram can be started from a Linux process.

So a min­i­mal ex­am­ple of the /etc/wsl.conf file to pro­hibit mal­ware ac­cess to any Win­dows drive would be

[automount]
enabled = true
options = "metadata,umask=222,fmask=222"
[interop]
enabled = false

In most cases, though, peo­ple in­stalling the Win­dows Sub­sys­tem for Linux may want to use the ad­van­tages of using Linux tools also with their Win­dows files.

If you want to know more about the pos­si­bil­i­ties of con­fig­ur­ing the file /etc/wsl.conf you can read all about that in Au­to­mat­i­cally Con­fig­ur­ing WSL.

In­stalling a graph­i­cal ed­i­tor

As a soft­ware de­vel­oper, I first need an ed­i­tor to cre­ate and edit the source code. So let’s try to in­stall the more and more pop­u­lar Vi­sual Stu­dio Code.

# install certificates so wget doesn't complain
sudo apt install ca-certificates
# get the latest VS Code installer package
wget -O code.deb https://go.microsoft.com/fwlink/?LinkID=760868
# install VS Code
sudo apt install ./code.deb
# install additional packages
sudo apt install libgconf-2-4 gconf2-common gconf-service libxss1 libdbus-glib-1-2 libasound2

At this point, we have a prob­lem. Vi­sual Stu­dio Code is based on Elec­tron, an open-​source frame­work al­low­ing for the platform-​independent de­vel­op­ment of desk­top GUI ap­pli­ca­tions. Un­for­tu­nately, Elec­tron does not run in a graph­i­cal en­vi­ron­ment with­out graph­ics ac­cel­er­a­tion. This is not a prob­lem in­her­ent to WSL, but to every re­mote graph­ics ter­mi­nal, es­pe­cially XRDP. To make it run, one can patch the li­brary file /usr/lib/x86_64-linux-gnu/libxcb.so.1, but that may break other ap­pli­ca­tions re­ly­ing on that li­brary. The best so­lu­tion seems to be to cre­ate a local patched copy of the li­brary and use it just for VS Code:

# make a copy of the library in the home directory
mkdir ~/lib
cp /usr/lib/x86_64-linux-gnu/libxcb.so.1 ~/lib
# modify the local copy
sed -i 's/BIG-REQUESTS/_IG-REQUESTS/' ~/lib/libxcb.so.1

To fi­nally start Vi­sual Stu­dio Code, we can now use the fol­low­ing com­mand line, set­ting the dy­namic loader path so Vi­sual Stu­dio Code uses the mod­i­fied li­brary:

LD_LIBRARY_PATH=$HOME/lib code

And again, if all is set up cor­rectly and the X Server is run­ning, the Vi­sual Stu­dio Code win­dow opens on the Win­dows desk­top.

Do you pre­fer Atom? No prob­lem:

# just in case you didn't do this before
sudo apt install ca-certificates
# get the latest Atom installer package
wget -O atom.deb https://atom.io/download/deb
# install Atom
sudo apt install ./atom.deb

Since Atom is also based on Elec­tron, we just use the same local patched li­brary ver­sion to run the ap­pli­ca­tion with­out graph­ics ac­cel­er­a­tion. If you didn’t in­stall Vi­sual Stu­dio Code be­fore, you first have to cre­ate the patched local li­brary as de­scribed above.

 LD_LIBRARY_PATH=$HOME/lib atom

The in­stal­la­tion of Sub­lime Text is just as easy:

# just in case you didn't do this before
sudo apt install ca-certificates
# install the GPG key
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
# ensure apt is set up to work with https sources
sudo apt-get install apt-transport-https
# select the stable channel so we can install it as a trial
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
# install sublime-text
sudo apt update
sudo apt install sublime-text
# start sublime-text
subl

And if you are still not con­vinced that the Win­dows Sub­sys­tem for Linux might be a vi­able al­ter­na­tive for de­vel­op­ing Linux soft­ware you can just in­stall Eclipse:

sudo apt in­stall eclipse

In­stalling a graph­i­cal file man­ager

To round it up, I tried to in­stall some graph­i­cal file man­ager. GTK based graph­i­cal ap­pli­ca­tions nor­mally need the dbus-x11 pack­age, so it’s best to in­stall that first:

sudo apt in­stall dbus-​x11

Desk­top in­de­pen­dent file man­ager like gen­too, Xfe, ROX-​Filer, SpaceFM, and PC­ManFM in most cases in­stall and run with­out prob­lems, whereas Thu­nar is miss­ing icons.

GNOME/GTK based file man­ager like Nau­tilus and Gnome Com­man­der seem to mostly work. As there is no real desk­top in­stal­la­tion, Nau­tilus com­plains about the trash not being ex­is­tent and just plain stops when click­ing on the Desk­top icon, un­less a folder named “Desk­top” is present in the home di­rec­tory. Gnome Com­man­der only com­plains about miss­ing icons. Nemo, a Nau­tilus fork for the Cin­na­mon desk­top en­vi­ron­ment, seems to work, but strangely brings its own desk­top win­dow.

With KDE based file man­ager your mileage may vary: Dol­phin in­stalls and runs in prin­ci­ple, but gen­er­ates a lot of warn­ings in the ter­mi­nal and the vi­sual rep­re­sen­ta­tion is bro­ken. Kon­queror in­stalls and, de­spite some warn­ing mes­sages in the ter­mi­nal, seems to run with­out prob­lems. The graph­i­cally sim­ple file man­ager Kru­sader in­stalls and seems to work.

Where to go from here

There is al­ready a lot of doc­u­men­ta­tion about the Win­dows Sub­sys­tem for Linux avail­able on the web. Below I have col­lected some links con­tain­ing a lot of ad­vanced in­for­ma­tion which go well be­yond the scope of this post. And of course, it will be very in­ter­est­ing which de­vel­op­ments in in­ter­op­er­abil­ity we will see in the fu­ture: a Win­dows Sub­sys­tem for Mac OS, maybe?

Mi­crosoft’s WSL doc­u­men­ta­tion

Michael Treat’s WSL setup guide on GitHub

Scott Hansel­man’s WSL Tips and Tricks

The WSL Guide