Installing and Getting Started with Bash on Windows

Written by:  • Edited by: Tricia Goss
Updated Nov 2, 2016
• Related Guides: Windows | Linux

This article will walk you through installing and configuring the Bash shell on your Windows 10 machine. It’s not quite as easy as just installing the Windows 10 update, but with the below steps you will be on your way quickly.

Getting Started

First up, you need to have a few things in place before we can dig into the how-to. In order to use Bash, you will need to be running Windows 10 with the Anniversary Update - specifically version 1607 or newer. You can determine your version by clicking the Windows menu, then type “About your PC." Select the appropriate shortcut and look for the “Version" row.

We are going to start by installing the “Windows Subsystem for Linux" which will give us access to Bash in Windows. With the Subsystem installed, you will be able to run certain Linux executables without the need to recompile them. However, this will not work for graphical programs. It’s really meant to help developers or tinkerers with command line utilities and programs.

Installing Bash

Installing Bash 

Figure 1

Let’s dive in. First up, we need to install the Windows Subsystem for Linux.

  1. Click the Windows button and type “Update.” Select the option to “Check for Updates.”
  2. In the Updates window, select “For Developers” from the left hand menu.
  3. Click the “Developer mode” button (Figure 1). Note that while you will be able to install apps from sources other than the Windows Store they will still need to be signed. It will be possible for you to install malicious software, but the chances should be small.
  4. Next, navigate to the Control Panel and then Programs. Select “Turn Windows Features On or Off.”
  5. Click the “Windows Subsystem for Linux” (Figure 2). Reboot if prompted to do so.
 

Figure 2

6. After you reboot, open the Windows button and type “bash.” Select the Bash button to open a new window.
7. You will be prompted to install Ubuntu on Windows. Type “y” and hit Enter.
8. After a few minutes, you will be prompted to create a user name – you can use “root” if you’d like. Note that this will give you administrative rights over the Bash session. You can create a different user (and password) if desired.

 

Learning How to Crawl

If this is your first time using Bash or any kind of Linux\Unix shell, keep reading, otherwise if you’re already an expert, you will already know what I’m about to cover. You can refer to Figure 4 and follow along.

 

Finding Your Way


In this simple example, we’ll use Bash to navigate to a local directory on our computer. We can use a few simple commands to navigate the file structure.

  • pwd – aka “print working directory" - this will tell you the current directory you are in
  • cd – aka “change directory" - this will allow you to change directories
  • ls – this will list the contents of the current directory

Another important concept in Linux is mount points. Think of this as shortcuts to external devices. Since Bash on Windows doesn’t really know about your Windows OS, it thinks of it as an external system. You can access your local Windows drives under the /mnt “directory."

Example Navigation


Using the above information, we can use these commands to navigate to the C:\Program Files directory. Type these as you go along.

  • pwd – you will see we are currently in the /root directory
  • cd .. – this will take us up a directory
  • ls – you can see all of the Linux directories present. Notice the /mnt directory – we’ll find Windows under there!
  • cd /mnt
  • ls – we can see my computer has a c and f drive
  • cd c – this takes us into the C: drive
  • cd “Program Files" – this will take us into the Program Files directory. Note the use of quotes is necessary because of the space between words.

A few things to note – Linux and Unix operating systems are case sensitive. If I had typed “cd ‘program files’" in the last line, it would have errored out.

In addition, you can combine “cd" statements instead of navigating one folder at a time. For example, at the /root directory, I could have typed “cd ‘../mnt/c/Program Files’" to take me directly to the Program Files directory.

There’s a lot more to cover – you can write Bash scripts to carry out tasks in an automated fashion, use Vi or Nano to edit documents and install utilities using the Ubuntu Apt commands. Let me know if there are any specific things you’d like me to cover in the comments down below!

 
blog comments powered by Disqus
Email to a friend