In­stall Linux on Win­dows

Try it with­out the has­sle: step-by-step guide

PC Pro - - Front Page -

When Win­dows 10 was first an­nounced, Mi­crosoft promised that reg­u­lar up­dates would add new ca­pa­bil­i­ties. Few of us imag­ined that this would in­clude a fully func­tion­ing Linux en­vi­ron­ment, but that’s ex­actly what we got in last year’s An­niver­sary Up­date.

To be pre­cise, the Win­dows Sub­sys­tem for Linux – WSL for short – isn’t a con­sumer-ori­ented graph­i­cal dis­tri­bu­tion like Ubuntu. How­ever, it con­tains all the un­der­pin­nings needed to run a Linux bash shell (the user in­ter­face) on your Win­dows PC. You get full ac­cess to the de­fault Linux tools, and you can in­stall soft­ware di­rectly from the Ubuntu repos­i­tory.

With a bit of tech­ni­cal wran­gling, it’s even pos­si­ble to run graph­i­cal ap­pli­ca­tions di­rectly on the Win­dows 10 desk­top, as we’ll dis­cuss. This isn’t re­ally what WSL’s in­tended for, how­ever: in Mi­crosoft’s words, the sub­sys­tem is “aimed at en­abling users to run bash and core Linux com­mand line tools on Win­dows. WSL does not aim to sup­port GUI desk­tops or ap­pli­ca­tions.” If you want to run Linux apps on a day-to-day ba­sis, it’s prob­a­bly a bet­ter idea to run a main­stream dis­tri­bu­tion in­side a vir­tu­al­i­sa­tion host, such as Hy­per-V – which is built into Win­dows 10

Pro­fes­sional – or the free Vir­tu­alBox hy­per­vi­sor ( vir­tu­

If you just want to run the odd tool or write the oc­ca­sional script, how­ever, WSL is the per­fect choice. And, be­cause it’s part of Win­dows, all your files are im­me­di­ately ac­ces­si­ble within bash – some­thing that can be a pain to set up with vir­tu­al­i­sa­tion.

At this point you might be won­der­ing what the ar­rival of WSL means for Pow­erShell, Win­dows’ own script­ing, man­age­ment and re­mote con­trol util­ity. The an­swer is the two are de­signed to co-ex­ist. Of­fi­cially, WSL is aimed at de­vel­op­ers who work with open-source projects, but oth­er­wise work largely in Win­dows. It will also ap­peal to macOS power users, since the bash com­mand line in­ter­face is ex­tremely sim­i­lar to Ap­ple’s Unix-based Ter­mi­nal.


If you’ve never used Linux be­fore, you’ll have a few new com­mands to learn. Type “help” to pull up a list of built-in com­mands, many of which will al­ready be fa­mil­iar (“dir”, for ex­am­ple) or ob­vi­ous (such as “lo­gout”). The prin­ci­ples of Linux are sim­i­lar to work­ing with the Win­dows com­mand prompt, but there are a few philo­soph­i­cal dif­fer­ences.

One is that the Linux file sys­tem isn’t fo­cused on dis­crete drives like Win­dows is. To see this in prac­tice, sim­ply open bash and a Win­dows com­mand prompt side by side and nav­i­gate to the root in each, by typ­ing “cd \” in com­mand prompt and “cd /” in bash. You’ll no­tice that com­mand prompt takes you to the top level of your hard drive (that is, C:\) while bash steps out of the drive al­to­gether, and lo­cates you at the root of the over­all file sys­tem.

Your cur­rent direc­tory is dis­played at the end of the prompt: for ex­am­ple, if you see “your­name@WINDOWS10:/ usr/lo­cal$”, that in­di­cates that any com­mands you en­ter will im­pact or ex­e­cute the con­tents of “/usr/”lo­cal. If this sim­ply shows “~$”, you’re in your own home folder. If you want to switch to a dif­fer­ent drive, you’ll find your phys­i­cal vol­umes in­side the “mnt” (mount) folder: to get to the C drive, type “cd /mnt/c”.

An­other dif­fer­ence is that while Win­dows doesn’t care about cases, Unix-based oper­at­ing sys­tems do. So, while “cd doc­u­ments”, “cd Doc­u­ments” and “cd DOC­U­MENTS” would each take you to the same place in the com­mand prompt, they re­fer to dif­fer­ent fold­ers in bash – and if you have a folder called “Doc­u­ments” it won’t be found if you en­ter “cd / doc­u­ments”. Spe­cial char­ac­ters such as spa­ces are han­dled dif­fer­ently, too: “cd Pro­gram Files” works fine in the com­mand prompt, but in bash you must “es­cape out” the space by pre­ced­ing it with a back­slash, thus: “cd Pro­gram\ Files”.

There are some neat con­ve­niences in bash. The “dir” com­mand lists your files and fold­ers on both sys­tems, but bash has an ex­tra trick. Use “dir -color”, and the re­sults are colour­coded to make di­rec­to­ries (blue) easy to dis­tin­guish from files (green). As in Win­dows, you can re­peat pre­vi­ous com­mands by sim­ply press­ing the up cur­sor key mul­ti­ple times to scroll through your his­tory. You can also type the first few char­ac­ters of a file or folder name, then hit Tab to have it au­to­mat­i­cally com­plete.


One of the best-known Unix tools is vim, a text ed­i­tor that’s been knock­ing around since the 1990s (and which is based on an ed­i­tor called vi that was orig­i­nally re­leased way back in 1976). It’s com­monly used for script­ing, as well as reg­u­lar text work. There’s no graph­i­cal in­ter­face, but its key­board com­mands are straight­for­ward to learn, and you can also en­able ba­sic mouse con­trol.

To try vim, start by nav­i­gat­ing to your Doc­u­ments folder: for se­cu­rity rea­sons, Linux lim­its your abil­ity to make changes out­side of your home folder. In our case, we’d achieve this by en­ter­ing “cd /mnt/c/Users/nik/ Doc­u­ments” (sub­sti­tute your own Win­dows user­name for “nik”). Then, en­ter “vim”, in lower case, fol­lowed by the name of the file you want to edit: for our pur­poses, we’ll en­ter “vim test.txt”, which will cre­ate a new file called

TEST.TXT, or open the file for edit­ing if it al­ready ex­ists.

When vim opens, it will be in Com­mand mode. To en­ter text, you must switch to In­sert mode by press­ing “i”. You can then im­me­di­ately start typ­ing into your doc­u­ment (you don’t need to hit re­turn af­ter the “i”). You should no­tice that the bot­tom line of the in­ter­face now says “IN­SERT”, and will stay like that the whole time you’re in this mode.

When you’ve fin­ished en­ter­ing your text, press Es­cape to re­turn to Com­mand mode. If you’ve writ­ten all you need, you can save the file and exit by typ­ing “ZZ”. If you want to quit with­out sav­ing, in­stead en­ter “:qa!”. Clearly, vim’s com­mands can be quite cryptic: luck­ily, you’ll find a use­ful cheat sheet at

One com­mand worth know­ing about is “:set mouse=a”, which makes the mouse ac­tive. This lets you click to move your cur­sor around within the doc­u­ment, rather than hav­ing to nav­i­gate through the key­board in­stead.


While WSL comes with a good set of de­fault tools, its full po­ten­tial lies in the abil­ity to in­stall ad­di­tional apps. This is very easy to do: bash can down­load soft­ware au­to­mat­i­cally from the Canon­i­cal repos­i­tory us­ing the apt-get com­mand (it stands for Ad­vanced Pack­age Tool). As an ex­am­ple, let’s in­stall Lynx, a textbased web browser that was pop­u­lar dur­ing the early days of the in­ter­net. In­stalling soft­ware must be done by a “su­pe­ruser” – the equiv­a­lent of an ad­min­is­tra­tor in Win­dows – so we use the “sudo” (“su­pe­ruser do”) com­mand to au­tho­rise it as fol­lows:

sudo apt-get in­stall lynx-cur

Af­ter en­ter­ing this com­mand, you’ll have to en­ter your pass­word to au­tho­rise the in­stal­la­tion. Once it’s in­stalled, you can test it by typ­ing “lynx” to nav­i­gate to the BBC’s web­site. Se­lect links us­ing the ar­row keys, and hit re­turn to fol­low them. Nat­u­rally, be­ing a text-based browser, the pages are stripped of their images and styling, so they load very quickly. To nav­i­gate to a dif­fer­ent page, press “g” and en­ter the ad­dress. Press­ing “delete” lists your his­tory, and “q” quits the app.

To re­move an ap­pli­ca­tion, you can use the same com­mand – sim­ply re­place the “in­stall” ar­gu­ment with “purge”:

sudo apt-get purge lynx-cur

An­other use for apt-get is keep­ing ap­pli­ca­tions up to date. Af­ter all, just as in Win­dows, it’s im­por­tant to in­stall patches and se­cu­rity up­dates as they be­come avail­able. Hap­pily, it’s very easy to keep on top of this: each time you launch bash you’ll be warned if up­dates are avail­able, and when you’re ready to in­stall up­dates you can up­date ev­ery­thing at

once by sim­ply en­ter­ing: sudo apt-get up­date


As we’ve noted, Mi­crosoft doesn’t cur­rently in­tend WSL to be used as a host for graph­i­cal apps. But that doesn’t mean you can’t do it – you just have to go to a lit­tle more ef­fort to get them work­ing. Fol­low th­ese steps:

1 Start by in­stalling an X server. X is the win­dow man­ager that han­dles Linux’s graph­i­cal front end. There are plenty of X server sys­tems, but we’ve opted for VcXsrc ( source­ In­stall it, then launch it from the Desk­top or Start menu. Choose to start it as mul­ti­ple win­dows.


In­stall the graph­i­cal ap­pli­ca­tion you want to use. We’re us­ing AbiWord ( –a free, open-source word pro­ces­sor. You can in­stall it us­ing apt-get in just the same way we did with Lynx: sudo apt-get in­stall abiword


We now need to tell the Linux sub­sys­tem where to dis­play the graph­i­cal ap­pli­ca­tion, since it doesn’t yet know about our X server. This is again per­formed by is­su­ing this com­mand and hit­ting re­turn: ex­port DIS­PLAY=:0

(Note that the last char­ac­ter is a zero.)


Launch AbiWord by typ­ing “abiword” at the bash prompt (all lower case). The app should now open in your X server win­dow. It’s not a per­fect im­ple­men­ta­tion: sav­ing can be a bit fid­dly, as side­bar lo­ca­tions such as Home and Desk­top are in­op­er­a­ble, but if there’s a graph­i­cal Linux ap­pli­ca­tion that you can’t live with­out, run­ning X on WSL could be your sim­plest op­tion.


Once you’ve given WSL a go, you may de­cide it’s not some­thing you need to use reg­u­larly – or you’d pre­fer a full graph­i­cal Linux in­stal­la­tion run­ning in­side a vir­tu­al­i­sa­tion host. Ei­ther way, you can re­move the Linux layer and re­claim some disk space: first, close bash; then open the Win­dows Com­mand Prompt and en­ter: lxrun /unin­stall /full

You’ll be prompted to con­firm that you’re happy to lose all of your Linux ap­pli­ca­tions and data. The en­tire WSL sys­tem will then be re­moved.


WSL re­mains in beta, and there’s still no au­thor­i­ta­tive doc­u­men­ta­tion. For more in­for­ma­tion, start with the FAQ on MSDN:

There’s a lot more in­for­ma­tion avail­able around the built-in Linux com­mands. For a quick guide, use the “-help” switch to show avail­able op­tions: for ex­am­ple, “dir -help” shows how to tai­lor the out­put of a direc­tory view. For com­pre­hen­sive doc­u­men­ta­tion, use the “man” (man­ual) com­mand: en­ter­ing “man vim”, say, will bring up an ex­ten­sive 19-page guide to vim. Press “q” to exit the man­ual reader.

RIGHT The text-based Lynx browser is fast, partly be­cause it ig­nores images and ad­vanced text styles

RIGHT The vim text ed­i­tor is a pop­u­lar de­vel­op­ment ap­pli­ca­tion, and is in­stalled with WSL by de­fault





Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.