How to Install and Run Bash on Windows 11

After installing WSL, you can run any Linux tools on your PC easily. So, if you want to run Bash on your Windows 11, here's how to do it in detail.

With the rise of open source culture, it is certainly impossible to ignore the great capabilities of the Linux operating system and replicate them to other operating systems. Microsoft understands this and it has successfully introduced Windows Subsystem for Linux (WSL).

Introduced in 2016, WSL is a Windows feature that allows you to run the Linux file system on your operating system. After installing WSL, you can run any Linux tools on your PC easily. So, if you want to run Bash on your Windows 11, here's how to do it in detail.

How to Install and Run Bash on Windows 11

Bash is the default shell for most Linux systems. First introduced in 1989 as a replacement for the Bourne shell, it also acts as a command-line interpreter for GNU-based systems.

Moreover, you can even use it as a word processor, graphics editing application or as your desktop, as Opensource.com explains.

So if you want to run Bash on Windows 11, you have to install WSL on your system first. Don't be intimidated by these complicated-sounding jargon; The whole installation process is quite simple. Here's how you can get started:

1. Go to the Start menu search bar, type 'terminal' and launch Windows Terminal with admin rights.

2. Enter the following command into Terminal:

wsl --install

3. Restart your PC once the installation is complete.

How to Install and Run Bash on Windows 11 Picture 1How to Install and Run Bash on Windows 11 Picture 1

As soon as your PC boots up, the installation will begin again. Your PC will start downloading and installing the Ubuntu software from here. You will soon be asked to set up a username and password. Do that and your PC will boot up quickly when you enter your password. The installation will automatically start from where you left off before starting your PC.

Finally, Ubuntu will be successfully installed on your PC. Once you're done, Ubuntu will automatically launch into the Bash shell. You can use the same commands you normally use in Linux, including installing Linux applications into this virtual environment.

How to Install and Run Bash on Windows 11 Picture 2How to Install and Run Bash on Windows 11 Picture 2

And that's how you can install and use Bash on your Windows PC. In fact, with Ubuntu on a current system, a host of other nifty features like alias, command line editing, task control, etc., will also be available to you.

How to Run Bash Scripts in Windows

To run a script in Bash, simply create a text file with your favorite file editor like Notepad and save it in a location you can easily remember.

One unique thing about Bash scripts is that the first line must be '#!' followed by the Linux bash path. To see what that is, launch Ubuntu and type bash into a command line window. This will give the Bash path.

How to Install and Run Bash on Windows 11 Picture 3How to Install and Run Bash on Windows 11 Picture 3

Create a new text file and include that first line at the top. In the case of this example, it would be:

#! /user/bin/bash

How to Install and Run Bash on Windows 11 Picture 4How to Install and Run Bash on Windows 11 Picture 4

Follow this line with each sequential command that you want Linux to run. In this example:

  1. Line 1: Use the echo command to display text to the user on the screen.
  2. Line 2: Combine echo with date command to return today's date.
  3. Line 3: Combine echo with the whoami command to return your username.

Save this text file with the .sh extension. Remember the path to this file.

Next, open Windows Terminal and use the cd command to navigate to the path where you saved the Bash script.

To run the script, type:

bash name_script

How to Install and Run Bash on Windows 11 Picture 5How to Install and Run Bash on Windows 11 Picture 5

This is a very simple example, but this shows how you can use such a file to generate entire Bash scripts. Even programming statements like IF statements are available to include decision-making in your scripts.

The SS64 website provides a rich resource with all the available Bash commands that you can use in your Bash terminal or your Bash scripts.

4 ★ | 5 Vote