How to Run Linux/Bash on Windows 10 Using the Built-In Windows Subsystem for Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there how's it going everybody in this video we'll be learning how to install and use the Linux bash shell on Windows 10 so for those of you who have followed along with my videos for some time now you know that I mainly used the Mac OS X operating system and occasionally I'll also do Linux tutorials using either a boon to or Kali Linux and I'm going to continue using those operating systems into the future but I also have a lot of people using Windows machines who contact me and say that they wish they could fall along with my terminal commands while on Windows so for those of you who are on Windows Windows 10 actually now comes with the option to use a Linux bash shell within windows which is really nice and this is a real bash shell this isn't a virtual machine or cygwin or anything like that that I may have suggested in the past so in this video we're going to learn how to use this feature so that you can use the Linux command line within Windows so let's go ahead and get started so first we need to turn this feature on so in the lower left corner of your screen let's click on the windows icon and within here let's just type features to search for that and the top result here should be turn Windows Features on or off and you can also find that in the control panel if you dig down within there as well so once we open that up let's scroll down here towards the bottom until you see it's on my machine it's for up from the bottom that says windows subsystem for Linux so let's check that to turn that feature on and click OK and that's going to run through a couple of things here first to apply those changes and once that finishes it says that we need to restart our computer for those changes to take effect so I'm going to restart now and I will pick up the video after my machine is rebooted ok so now my machine has been restarted and I have logged back in now at this point there are a couple of different ways that we can get to the next step so the first way is if we open up our command prompt on Windows and then we type in bash and press Enter then we can see that it says that the windows subsystem for linux has no installed distributions and that we can install those by visiting the Windows Store and it provides a link here so we could paste that into a browser and it would take us to a list of those distributions in the Windows Store now another way that we can get to this step is just to simply open up the Windows Store so whichever way is easy for you so I'm gonna open up the Windows Store here so I could have either followed that link or you can come in here and type in Linux or a boon to so I will type in Ubuntu and press enter and when we search for that we can see that the first option here says Linux on Windows and then we can click to go get the apps and also listed down here and the apps we can see a boon to listed here so I'm gonna click on get the apps just to see all the different listings here so we can see within here we have a boon - and two others listed so for this video I'm going to install in boon too so I'm going to click on this and install it now this might take a second so I'm just going to fast-forward to the point where this installation is complete okay so once that installation is complete then you should get a notification here where you can launch this but if you accidentally closed that down or don't see that then we can actually launch this from the Start menu as well so if we open up the Start menu here then we should be able to see a boon - in here so now I'm going to open this up and now this is going to say that it's going to install some additional things and this could take a few minutes and also notice that when we open this we open this using the Ubuntu app we did not open the Windows command prompt so we'll look at running bash through our Windows command prompt soon but for now just be sure that you opened up the aboon - app so all of these long installations are just one-time things so don't worry you're not going to have to go through this more than once so I'm gonna fast forward this video here until this installation is complete okay so once that installation is complete then you should see a screen like this where it's asking for a unix username so for this i'm just going to type in core ems and hit enter and then it's going to ask for a password so i'm just going to put in a password really quick here and they'll ask to confirm that so i'll put in the same one okay so once you put in that information then you should see this screen here so this is our linux environment so let me make this text a little bit bigger here really quick so that everyone can see so let's say I'll bump this up to 36 font and also actually I think that's fine right there so I'm just going to cancel out of that so now let me maximize this here and clear the screen so now we can use Linux commands like you may have seen in some of my other videos so if we print the current working directory and just do a PWD then you can see that we are in this home core ems folder and i'll it if i list all the files in this folder with an LS - la then we can see that we have a few dot files here now it's not entirely clear where we are on our system here like if we wanted to actually see some files on our Windows machine then where is our desktop and things like that well in the windows subsystem for linux our machine is accessible through a mount and in a minute i'll show you how to make a shortcut to this location but for now let's just navigate to that location and see what's there so to do this let's do and and I'm going to clear my screen let's do an LS on this mount folder here from the root directory and within Mount I can see this C directory and that is the C Drive on my machine so let's CD into that so I'm going to do a CD in to mount and into that C directory and now let's list what we have in here so I'm going to list everything so I'm going to do an LS - la so now within here we can see that we have our Program Files and users and things like that so now let's try to CD into my personal desktop so that is going to be within users so I will CD to users and then do an LS and we can see that we have this Quarry directory here so that's what it is on my machine it's going to be different on yours so now I'm going to clear my screen and CD into my home folder for my Windows machine so now if I do LS and there then we can see we have a lot of stuff here but one of these is the desktop and documents and downloads and things that you're used to seeing on your home user folder so let me CD to that desktop and hit enter and clear my screen and then do an LS la here okay so now let me clear out this screen here and now let's see if we can actually work with some files on Windows using bash so first let's try to create a file so let me say touch test dot txt and hit enter and actually this text might be just a little bit too big here so let me take this down a little bit here I'll do a size 32 font and I think that should still be readable but also can fit on one line there okay so now if I look at my Windows desktop here then we can see that it actually did create this test txt file on the desktop so that did work so what about editing this file within Linux so let's try to edit this file using Nano which is an easy text editor to use in bash so I will do a nano test txt and hit enter and this opens up the Nano editor so within here let's just say testing file and then I will close out of this and and when within Nano this is control X and hit Y to save and then hit enter to keep that file name and now if we cat the contents of that file to see what's in there so cat test text est then we can see that it did write that to the file ok awesome so this is working well so at this point if you're familiar with the linux and the command line then that is pretty much all you need to do in order to begin using it on windows so at this point you could stop watching the video and you'd be able to follow along with my command line videos in the future but for those of you who are interested I figured I'd also go over a few extra steps and show a few more things that we can do with this so first of all you can also install additional programs using the apt-get install so for example let's say that we wanted to use the tree command which is basically a nice way to see our file and directory structure so if we try to use this now and just type in tree then we can see that it says the program tree is currently not installed you can install it by typing sudo apt-get install tree now you could go ahead and run that but before that let's update and upgrade our packages so that we have the newest versions of everything and this can take a long time so just be aware of that and to do this we can do sudo apt-get and update to update to the latest versions and we need to type in our password here ok so now that's done with the update and also that password that I used for the sudo command that was the password that we specified for the unix user so be aware of that ok so now I'm going to clear this out and now I'm actually going to do an upgrade so instead of update we will do sudo apt-get upgrade and run that and we'll have to hit yes to continue here and now it will run through those upgrades and that can take a while so I'm going to skip forward until this is complete okay so once that is complete let's go ahead and install tree so to do this we can do sudo apt-get install tree and then need the sudo password again so then that should run through the installation and this one should be fairly quick okay so once that's complete we should be able to use the tree command so if we run that then we can see that we get this nice file and directory structure using the tree program that we just installed okay so now one last thing that I'd like to do is specify an alias so that we can quickly switch to our Windows home folder instead of needing to remember that it's under this mount seed directory so for now I'm going to change back to the Linux home directory and we can do that just by typing CD and now to create an alias we can edit the dot bash RC file in our home directory and we can do that so I'll just open that up in Nano so I will do the ampersand which is the same as our home directory that dot bash RC so open that up and within here we can see that it came with some stuff in this file already so let's just go down here below the part where it checks if this is running interactively or not and then we will put our alias in here so we can do this I'm just going to do an alias and I'll call this win home and equal to and no spaces between any of this and we want that to be equal to CD and then we'll just go to the home directory that I was just in so on my machine that is within users and quarry so now anytime I type win home it's actually going to do a change directory into this location and that is my windows home folder so now I'm going to exit out of this by hitting ctrl X since I'm in Nano Y to save and then enter to just keep the same filename now after we've saved that we need to source that file for those changes to take effect so we can just do that with ace and then the same file the dot bash RC file and our home directory and once we do that then we should be able to navigate to our windows home directory just by saying when home and hitting enter and you can see that we did CD to that directory okay so one more quick tip when working with bash on Windows so let me close this out here and open up the Windows command prompt and let me enlarge this so if you are ever using the Windows command prompt and want to switch over to using bash then you can easily do that just by typing bash and it will open up a bash terminal in the directory that you're currently in so when I first opened this it puts me in my home directory so let me navigate to my desktop and the command for that is the same on Windows as it is in bash we can just do CD desktop and hit enter and now that I'm on my desktop let's say that I wanted to use the grep command to search for some text within a names txt file that's in a demo folder here on my desktop now if I try to do this here in Windows command prompt so let me do a grep with some options of in I don't worry if you don't know grep it's not a big deal for this video I just wanted something to give an example here so the file that I want to grep and search for this name is within this demo folder and names.txt so if I run this within Windows it's not going to know what you're talking about it's gonna say that grep is not a recognized command so we really want to use bash here so if I type bash then it's going to open up our Linux terminal here and you can see that we're all it already put us in the location where we currently were in the Windows command prompt so that was on my desktop and now if I type out that command again and do the same search so let me type this out here and that was within demo and names.txt so now if I run that then you can see that that work just fine within a bash and we got the results that we were hoping to find and then to exit back out to our Windows prompt we can just type exit and it takes us back to our desktop where we currently were before we even went in okay so I think that is going to do it for this video now there are many more customizations that you can make to your bash terminal and I have some videos on that subject that I'll link to in the comment section below if anyone is interested in those so now after this video hopefully anyone using Windows should be able to follow along with any of my command line tutorials if those have ever been of any interest to you so for example I'll be releasing a video soon on how to use the grep command in depth and we saw that for a second in this video but grep is an extremely useful text searching tool in the command line especially once you learn the ins and outs to search for exactly what you want and I'll be using my Mac in that tutorial video but with bash now available on Windows 10 more of you should now be able to follow along with that video as well so if anyone has any questions about will be covered then feel free to ask in the comment section below and I'll do my best to answer those and if you enjoy these tutorials and would like to support them then there are several ways you can do that these displays - simply like the video and give it a thumbs up and also it's a huge help to share these videos with anyone who you think would find them useful and if you have the means you can contribute through patreon and there's a link to that page in the description section below be sure to subscribe for future videos and thank you all for watching you
Info
Channel: Corey Schafer
Views: 478,569
Rating: undefined out of 5
Keywords: windows, linux, linux on windows, bash, bash on windows, windows 10, windows subsystem for linux, subsystem, corey schafer, grep, ubuntu, subsystem for linux, windows linux, windows bash, command-line, command line, windows command prompt, windows command line tutorial
Id: xzgwDbe7foQ
Channel Id: undefined
Length: 14min 31sec (871 seconds)
Published: Wed Feb 21 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.