How To Run the Bash Command Line in Windows 10

Was this page helpful?

 

In the Windows 10 Anniversary Update, Microsoft added an interesting new feature for developers, power users, and anyone used to working with Unix-y systems such as Mac OS X and Linux. Windows 10 now includes the Unix Bash command prompt (in beta) courtesy of a collaboration with Canonical, the company behind Ubuntu Linux.

With the Bash command prompt, you can carry out all kinds of actions such as interacting with the Windows file system (just as you can with the regular Windows command prompt), running standard Bash commands, and even installing Linux graphical UI programs--although that last one isn't officially supported.

If you're a seasoned Bash user or interested in getting started with the popular command prompt, here's how to install Bash on Windows 10.

01
of 06

The Subsystem

Developer mode Windows 10

When you install Bash on Windows 10 you aren't getting a virtual machine or a program that does its best to mostly run like Bash in Linux. It's actually Bash running natively on your PC thanks to a feature in Windows 10 called the Windows Subsystem for Linux (WSL). The WSL is the "secret sauce" that allows Linux software to run on Windows.

To get started, go to Start > Settings > Update & Security > For developers. Under the sub-heading "Use developer features" select the Developer mode radio button. You may be asked to restart your PC at this point. If so, go ahead and do that.

02
of 06

Turn On Windows Features

Windows Subsystem for Linux

Once that's done, close the Settings app and click on the Cortana search bar in the taskbar and type in Windows features. The top result should be a Control Panel option called "Turn Windows features on or off." Select that and a small window will open.

Scroll down and check the box labeled "Windows Subsystem for Linux (Beta)." Then click OK to close the window.

Next you'll be prompted to restart your PC, which you will have to do before you can use Bash.

03
of 06

Final Installation

Bash

Once your computer has restarted, click on Cortana in the taskbar once again and type in bash. The top result should be an option to run "bash" as a command--select that.

Alternatively, go to Start > Windows System > Command Prompt. Once the command prompt window opens type in bash and hit Enter.

Whichever way you do it, the final install process for Bash will start by downloading Bash from the Windows Store (via the command prompt). At one point you'll be asked to continue. When that happens just type y and then wait for the installation to complete.

04
of 06

Add A Username and Password

Bash username and password

When everything is almost done you'll be asked to enter a username and password, as is typical for Unix command prompts. You don't have to use your Windows user account name or password. Instead, they can be completely unique. If you want to call yourself "r3dB4r0n" then go for it.

Once that part is done and the installation completes, the command prompt will open automatically into Bash. You'll know it's done when you see something like 'r3dB4r0n@[your computer name]' as the command prompt.

Now you're free to enter any Bash commands you like. As this is still beta software not everything will work, but for the most part it will operate similarly to Bash on other systems.

Whenever you want to open Bash again you'll find it under Start > Bash on Ubuntu on Windows.

05
of 06

Upgrading Your Installation

Bash on Ubuntu on Windows

As any good Bash user knows before you do anything with the command line you should update and upgrade your current installation of packages. If you've never heard the term, packages are what you call the collection of files that make up command line programs and utilities installed on your machine.

To make sure you're up to date, open Bash on Ubuntu on Windows and type the following command: sudo apt-get update. Now hit Enter. Bash will then print an error message to the window and then ask for your password.

Just ignore that error message for now. The sudo command isn't fully working yet, but you still need it to carry out certain commands in Bash. Plus it's just good practice to do things the official way in anticipation of a seamless Bash experience on Windows.

So far all we've done is updated our local database of installed packages, which lets the computer know if there's anything new. Now to actually install the new packages we have to type sudo apt-get upgrade and hit Enter once again. Bash probably won't ask for your password again since you just entered it. And now, Bash is off to the races upgrading all your packages. Early on in the process Bash will ask you if you really want to continue upgrading your Bash software. Just type y for yes to carry out the upgrade.

It may take a few minutes to upgrade everything, but once it's done Bash will be upgraded and ready to go.

06
of 06

Using A Command Line Program

Rsync

Now we've got Bash up and running it's time to do something easy with it. We're going to use the rsync command to do a back-up of our Windows documents folder to an external hard drive.

In this example, our folder is at C:\Users\BashFan\Documents, and our external hard drive is the F:\ drive.

All you have to do is type in rsync -rv /mnt/c/Users/BashFan/Documents/ /mnt/f/Documents. This command tells Bash to use the program Rsync, which should already be installed on your version of Bash. Then the "rv" part tells rsync to back-up everything contained inside the various folders in your PC, and print out all of rsync's activity to the command line. Make sure you type this command exactly including the use of the trailing slash after .../BashFan/Documents/. For an explanation on why that slash is important check out this Digital Ocean tutorial.

The last two bits with the folder destinations tell Bash which folder to copy and where to copy it to. For Bash to access Windows files it has to start with "/mnt/". That's just an oddity of Bash on Windows since Bash still operates as if it's running on a Linux machine.

Also note that Bash commands are case sensitive. If you typed in "documents" instead of "Documents" Rsync would not be able to find the right folder.

Now that you've typed in your command hit Enter and your documents will be backed up in no time.

That's all we're going to cover in this introduction to Bash on Windows. Another time we'll take a look at how you can experiment with running Linux programs on Windows and talk a little bit more about common commands to use with Bash.