Microsoft recently launched Bash on Ubuntu on Windows 10 — a shell environment with most of the Linux CLI tools and utilities. Using the same, you can run
awk and many more tools directly in Windows without the need to switch to Linux distro.
10 Most Asked Questions About Linux
You have probably heard of Linux as the free alternative to Windows and OS X. It's one of…Read more
Even if you never tried out Unix or Linux, here’s your chance to learn and experiment with Bash and other *NIX tools in Windows 10. In this introductory tutorial, we’re going to share how to get started with Bash on Windows 10 and use them in various ways.
What’s Bash on Ubuntu on Windows 10?
Bash (Bourne Again SHell) is a text-based shell and a scripting language for Unix and Linux platforms. Bash on Ubuntu on Windows 10 is an optional feature that’s available for people using Windows 10’s Anniversary Update.
It runs on the top of Windows Subsystem for Linux (WSL) and lets you experience Linux right inside your Windows PC.
This new technology enables you to run *NIX commands and compatible command-line tools natively in Windows. You no longer need to install a Unix or Linux distro side by side your Windows OS or setup a virtual machine for trying out *NIX OS.
Compared to a virtual machine, Bash on Ubuntu requires fewer system resources, and lets you access both Windows and Linux tools at the same time.
Bash on Windows 10 is especially useful for developers and system administrators working on open-source projects. This feature comes as an unpredicted gift from Microsoft with support of Canonical.
This is to bridge gap between the proprietary Windows with the free and open source Linux technologies starting with Bash shell.
- Run *NIX command-line utilities like
- Run shell scripts (.sh) with supported command-line utilities
- Browse and modify the local Windows file system using Bash
- Try various *NIX-first tools and utilities like Python, Ruby, Git, etc.
- Supports server tools like Apache HTTP Server, MySQL and more
- Doesn’t run GUI tools natively (though there’s a trick given below)
- Doesn’t allow Bash scripts to execute Windows programs and vice-versa
How to Install Bash on Ubuntu on Windows 10?
Bash on Ubuntu on Windows 10 is installable manually if your system runs on Windows 10 having Anniversary Update (build 14393 or later) and supports 64-bit processor. Follow these steps to confirm that your system meets these requirements:
- Open Settings > select System > select About
- Look for the following information: OS Build and System type
After verifying the requirements, you can install Bash using the following steps:
- Open Settings > select Update & security > select For developers
- Under Use developer features > select Developer mode option, and Windows 10 will search and install the developer mode package
Note: Bash will install despite the error message shown as in below pic.
Now enable the Windows Subsystem for Linux (an optional feature) using these steps:
- In the Start search box, type “turn” and click on Turn windows features on or off
- Select Windows Subsystem for Linux (Beta) and click OK
- After installing the Windows Subsystem for Linux, restart your computer if it is asked
- In the Start search box, type “cmd” and open Command Prompt
- Type “bash” in the Command Prompt window and hit Enter
- Type “y” to accept the license terms (you can also check them at the given link)
- Windows Subsystem for Linux will now download and install Bash on Ubuntu, and will place a shortcut for the same in the Start menu
- After Bash is installed, you need to create a UNIX username and password
Note: It need not be same as your Windows account’s name and password.
Congrats — you’re done installing Bash on Ubuntu on Windows 10 now. You can launch it using the Start menu and enjoy running Unix and Linux utilities now.
How to Use Bash on Ubuntu on Windows 10?
After the installation, you can enjoy using Bash with root (“administrator” in Windows term) or full access permissions in Windows 10. The local file system (C: drive) is located in the
/mnt/c directory in this shell environment and same as for your drives.
Note: Same as *NIX systems, Bash on Windows 10’s environment is also case-sensitive, i.e., the names ‘ash’, ‘Ash’, ‘AsH’ and ‘ASH’ are all different.
How to Install More *NIX Tools and Utilities?
You can install additional software or update the present tools using the known
apt-get command with the prefix
sudo to run them as root or administrator in Windows.
Below is a list of apt-get commands you can use to install *NIX software:
sudo apt-get update– Update package list information (list of software available to download along with their version numbers)
sudo apt-get install <package-name>– Install a new application package (replace “<package-name>” with the package name to install)
sudo apt-get remove <package-name>– Uninstall a present application package (replace “<package-name>” with the package name to remove)
sudo apt-cache search <query-word>– Search for available packages (replace “<query-word>” with the package name to search)
sudo apt-get upgrade– Download and update the installed software packages
After downloading and installing an application, you can type its name in Bash shell (without any extension) and hit Enter key to run the same.
Do note that Linux-based tools and utilities are restricted to run in the Bash shell only.
How to Run Bash Scripts?
In the Bash shell, you can use
vi editors to create shell scripts. After creating the script with required set of commands, save and close the editor, and then follow these steps to run your command-line script:
- Make the script executable by using
chmodcommand, for example,
chmod +x ./myscript.shfor a script named “myscript.sh” present in the current directory
- Run the script in the terminal by specifying its full path, for example,
./myscript.shfor a script named “myscript.sh” present in the current directory
How to Run Linux Commands Outside Bash?
You don’t need to launch the Bash shell first to execute a *NIX command, rather run a script or launch a program. You can run the command directly using
bash -c, which can be used for various purposes like:
- To create desktop shortcuts
- To launch Linux programs directly from Run tool
- To call Linux commands in batch or PowerShell scripts
For example, you can do the following steps to launch the vi editor:
- Press Win + R to launch the Run tool
- In the Run window, type
bash -c "vi"and click OK to launch the vi editor
How to Run GUI Programs using Bash?
Bash on Ubuntu on Windows 10 doesn’t support GUI software natively, but can run some graphics-based tools using the old VNC trick. The trick requires an ‘X Server’ running on your Windows and Bash on Ubuntu configured to route the graphics to that server.
Here’s the step-by-step procedure to achieve the result:
- Install an X Server application in Windows like Xming
- Install the GUI program in Bash using the
apt-getcommand, for example, run
sudo apt-get install vim-gtkto install the GTK-based Vim editor
- After it’s installed, run
export DISPLAY=:0in Bash.
Note:You must run this command every time you reopen Bash
- Now launch the GUI *NIX tool by running its executable’s name in Bash, for example, execute
gvimto launch the GTK-based Vim editor
Note: All *NIX-based GUI programs are not yet supported by this trick, so if your favorite program doesn’t work, don’t worry and wait for official support in future updates. Also, you may receive system crashes while running few GUI tools owing to the same reason.
Common & Useful Bash Commands
Bash on Ubuntu Windows 10 supports various common commands and avails numerous command-line utilities to help achieve daily tasks and write useful scripts. Here’s a list of common Unix and Linux commands to help you get started with Bash.
Wrap up — It’s a Good Start
Bash on Ubuntu on Windows 10 proves to be a new dawn with Microsoft finally availing support for free and open source software on its Windows platform. This allows developers to leverage the open-source developer ecosystem without side-loading Linux or using a virtual machine.
Basic Shell Commands For Bloggers
The system of shell commands is one of the oldest languages for systems communications. Computers have been able…Read more
However, the *NIX apps can’t interact with or launch Windows programs directly, but it’s just a start, so let’s keep our heads up for the great possibilities ahead.
How do you feel about Bash on Ubuntu, and which features you’d like to see for Bash on Ubuntu in future updates of Windows 10? Kindly share your thoughts using comments.