Microsoft built new infrastructure within Windows – the Windows Subsystem for Linux (WSL) – upon which we run a genuine Ubuntu user-mode image provided by Microsoft great partners over at Canonical, creators of Ubuntu Linux. The result is that you can now run native Bash on Ubuntu on Windows.
Enable Windows 10’s Ubuntu Bash Shell
Before we started, ensure that you’ve install the Windows 10 Anniversary Update. This only works on 64-bit Windows 10.
Step 1 - Enable Developer Mode
To enable Developer Mode open the Settings app and head to Update & Security > For Developers. Press the Developer Mode switch.
Step 2 - Enable the Windows Subsystem for Linux
To enable the Windows Subsystem for Linux (Beta), open the Control Panel, click Programs and Features, and click Turn Windows Features On or Off in left side bar under Programs and Features. Enable the Windows Subsystem for Linux (Beta) option in the list here and click OK. After you do, you'll be prompted to reboot your computer. Click Restart Now to reboot your computer and Windows 10 will install the new feature.
Step 3 - Download the Bash on Ubuntu on Windows
After your computer restarts, click the Start button (or press the Windows key), type bash, and press Enter.
The first time you run the bash.exe file, you'll be prompted to accept the terms of service. The command will then download the Bash on Ubuntu on Windows application from the Windows Store. You'll be asked to create a user account and password for use in the Bash environment.
If you'd like to automate the installation of Bash instead, you can run the following command in a Command Prompt window. This will automatically agree to all prompts and set the default user to root with no password:
lxrun /install /y
Step 4 - Use Ubuntu's Bash Shell on Windows
You’ll now have a full command-line bash shell based on Ubuntu. Because they’re the same binaries, you can use Ubuntu’s apt-get command to install software from Ubuntu’s repositories. To open the Bash shell, just open your Start menu and search for “bash” or “Ubuntu.” You’ll see a “Bash on Ubuntu on Windows” application.
If you’re experienced using a Bash shell on Linux, Mac OS X, or other platforms, you’ll be right at home. You don’t need to use sudo, as you’re given a root shell. The “root” user on UNIX platforms has full system access, like the “Administrator” user on Windows. Your Windows file system is located at /mnt/c in the Bash shell environment.
Use the same Linux terminal commands you’d use to get around. If you’re used to the standard Windows Command Prompt with its DOS commands, here are a few basic commands on both Bash and Windows:
- Change Directory: cd in Bash, cd or chdir in DOS
- List Contents of Directory: ls in Bash, dir in DOS
- Move or Rename a File: mv in Bash, move and rename in DOS
- Copy a File: cp in Bash, copy in DOS
- Delete a File: rm in Bash, del or erase in DOS
- Create a Directory: mkdir in Bash, mkdir in DOS
- Use a Text Editor: vi or nano in Bash, edit in DOS
It’s important to remember that, unlike Windows, the Bash shell and its Linux-imitating environment are case-sensitive. In other words, File.txt with a capital letter is different from file.txt without a capital.
Watch this video to learn more and to see Bash running on Ubuntu on Windows!