+4 votes
29 views
How to install and run Bash on Windows 11

in Guides by (551k points)
reopened | 29 views

1 Answer

+5 votes
Best answer

Install and run Bash on Windows 11
Run commands in Windows

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 it in others. It is possible to install and run Bash on Windows 11 thanks to Microsoft successfully introducing 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 Shell Bourne, in turn it 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 will write Terminal, we will 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 begin again. Our PC will download and install the Ubuntu software at this time. It will ask us to enter a username and password. When we do this, our PC will start, it will start 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 installing Linux applications in this virtual environment.

Run commands in Windows

In order to run 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.

Something important 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 .sh extension in a location that we can remember. After this we are going to open the Windows Terminal and use the “cd” command to navigate to where we have saved the Bash script. For example: bash name_script

In reality, 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 to be able to generate more complex Bash scripts.



by (3.5m points)

Related questions

+3 votes
1 answer
+4 votes
1 answer
asked Nov 20, 2021 in Guides by backtothefuture (551k points) | 83 views
+5 votes
1 answer
asked Nov 18, 2021 in Guides by backtothefuture (551k points) | 95 views
+5 votes
1 answer
+5 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

  1. Cell phone location by number: How easy it is to do it in Latam
10,634 questions
10,766 answers
510 comments
3 users