Site icon WPDig.com

How to install and run Bash on Windows 11

Thanks to the great popularity of “open source” it is impossible to ignore the great capabilities of an operating system like Linux and try to replicate them in others. it’s possible install and run Bash on Windows 11 thanks to Microsoft’s successful introduction of the Windows Subsystem for Linux (WSL).

What is WSL? This is a feature introduced in 2016 that gives us the ability to run the Linux file system on the current operating system. After installing WSL, it is possible to run any Linux tool on our Windows computer.

Install and run Bash on Windows 11

Bash is the standard shell that most Linux systems have. The first time we saw it was in 1989 as a replacement for the Bourne Shell, which in turn serves as a command line interpreter for GNU-based systems.

It is even possible to use it as a word processor, a graphics editing app or as our desktop. Therefore, if what we want is to install and run Bash on Windows 11, the first thing we will do is install WSL on our system. The process is quite simple, so we shouldn’t have any kind of problem.

The first thing we will have to do is go to the Start menu and then we are going to write Terminal, we start Windows Terminal with administrator permissions from the right panel. Once opened, we will have to enter the following command: wsl –install

Once the installation is complete, we will proceed to restart the computer.

After our PC boots, the installation will start again. Our PC will download and install the Ubuntu software at this point. It will ask us to enter a username and password. When we do this, our PC will start up, it will boot up quickly. The installation will automatically start from where we left off before starting the PC.

Now Ubuntu will be installed on our computer. When finished, Ubuntu automatically boots into the Bash shell. It is possible to use all the commands that we use in Linux, including the installation of Linux applications in this virtual environment.

Run commands on Windows

To be able to execute a script in Bash, we are simply going to have to create a text file with our favorite editor, it can even be notepad. Then we will have to save it in a location that we remember.

An important thing in Bash scripts is that the first line has to be “#!” followed by the Linux bash path. In order to visualize this, we will start Ubuntu and type bash in a command line window. This will give us the Bash path.

So let’s create a text file with any editor and include this line at the top. For example: #! /user/bin/bash

We will follow this line with each sequential command that we want Linux to execute:

  • First line: we will use the echo command to display text on the screen.
  • Second line: We will combine the echo command with date to return the current date.
  • Third line: We combine echo with the whoami command to return the username.

We will save the text file with the extension .sh in a location that we can remember. After this we are going to open the Windows Terminal and use the “cd” command to be able to navigate to where we have saved the Bash script. For example: bash name_script

Actually, the example that we mentioned above is quite simple, but it serves to make it clear how it is possible to execute a file of this type in order to generate more complex Bash scripts.

Exit mobile version