JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Add WSL Bash Shell to Windows

Author:JIYIK Last Updated:2025/03/20 Views:

Microsoft's recent embrace of Linux has resulted in some great features in Windows. The centerpiece of this effort is the Windows Subsystem for Linux (WSL), a lightweight virtual machine capable of running a full Linux distribution entirely within Windows, eliminating the work for users to set up a virtual machine or dual-boot setup.

After installing WSL, users have access to a command-line shell, in most cases Bash, allowing developers familiar with UNIX to start using their favorite tools immediately after setting up WSL by simply launching Bash in a new window.

This tutorial will show you how to set up the Windows Subsystem for Linux (WSL) to add the Bash shell to Windows. The following information comes from Microsoft's information page on installing WSL.


Initial Requirements

To make sure we have the latest version of Windows, press Windows 键+ Rand enter winver. You should see at least Windows 10 (version 2004) or Windows 11 in the window that appears.

If you have an older version, you may want to consider upgrading to the newer version. If that's too inconvenient, you can follow Microsoft's instructions for installing WSL on older Windows versions here.


Install WSL for the latest versions of Windows

If you see a recent or newer version, you can install WSL by opening an Administrator PowerShell window and entering the commands described below. The images are from Windows 11, but the same instructions apply for Windows 10.

  • Open the Start menu.
  • Start typing powershell.
  • You should see the following.

  • Press Ctrl+ Shift+ Enterto launch an Administrator PowerShell window.
  • Accept the User Access Control that may appear and the blue PowerShell prompt should appear as shown.

In this window, type in wsl --install. By default, it will install WSL and set it up with the very common Ubuntu distribution.

Additionally, you can install another Linux distribution by typing wsl --list --onlineand then wsl --install -d <linux_distribution>listing the available Linux distributions.

For example, if you wanted to install Debian instead of Ubuntu, you would type wsl --install -d Debian.

Once the command finishes running, it may instruct you to restart your computer. Once it’s finished, open 开始the menu and enter . Press Enter to start WSL. You can even start WSL wslby entering in a PowerShell window .wsl


Running WSL Bash Shell for the First Time

The first time you run WSL, it may require login information - remember, you just installed a full Linux distribution, so it requires a username and password. Enter these details, and remember that they don't have to be the same as your Windows username and password.

After setting up WSL, it should launch a Bash shell and it should look similar to the image below.

You should be able to try out some basic commands on your newly acquired Bash shell - mkdircreate a folder with , touchcreate a file with , nanoedit it with , list the files in your Windows home directory (which is where the WSL Bash shell will start by default).

To copy files from C:\\a drive, navigate to /mnt/cthe installation directory.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Run batch (.bat) files in CMD

Publish Date:2025/03/20 Views:155 Category:OPERATING SYSTEM

This article will show you how to use CMD to run a batch file.bat. There are three ways to run a batch file. Let us discuss them in the following sections. Run batch (.bat) files in CMD by directly clicking on them This way you can just go

Changing CMD text color using batch script

Publish Date:2025/03/20 Views:171 Category:OPERATING SYSTEM

This article will first discuss the basic concepts of batch scripts or batch files. After introducing the Batch script, let's discuss how to use the Batch script to change the text color of CMD every second. Batch script or file A batch scr

Batch set command timeout

Publish Date:2025/03/20 Views:50 Category:OPERATING SYSTEM

This article will first discuss the concept of timeout command in batch scripting. After that, we will discuss setting timeout command for any other command. Timeout command in batch script A timeout is a utility that pauses or delays for a

Batch merge XML files

Publish Date:2025/03/20 Views:101 Category:OPERATING SYSTEM

This article will first discuss and understand the XML file format. After that, we will discuss merging two or more XML files into one file using batch commands and scripts. XML File XML, also known as Extensible Markup Language, is a marku

Run .exe file from command prompt using batch script

Publish Date:2025/03/20 Views:76 Category:OPERATING SYSTEM

This article will show you how to use a batch (.bat) script to run a .exe type file. You can use two different commands to achieve this. Let’s discuss each method in the following sections. Run .exe file from command prompt using title an

Deleting files older than N days using batch script

Publish Date:2025/03/20 Views:57 Category:OPERATING SYSTEM

In this article, we will use a batch script to delete files older than N days. Deleting files older than N days using batch script The general format of the code to perform this task is shown below. FORFILES /p "D:\DIRECTORY" /S /M *.* /D -

Deleting files using batch script

Publish Date:2025/03/20 Views:178 Category:OPERATING SYSTEM

This article will demonstrate how to delete files using a batch script. Deleting files using batch script Generally, we can easily delete files by clicking on delete or pressing the delete button on the keyboard. But in Batch, we have to fo

Concatenate multiple files using batch script

Publish Date:2025/03/20 Views:195 Category:OPERATING SYSTEM

In this article, we will see how to concatenate multiple files into one file. Concatenate multiple files using batch script The general format of the commands we will use is shown below. type FileONE.txt FileTWO.txt ConcatFile.txt There are

Check if a file exists using batch processing

Publish Date:2025/03/20 Views:100 Category:OPERATING SYSTEM

This article will demonstrate how to use a batch script to check if a file exists through sample code. Check if a file exists using batch script The general format or syntax of the code to check if a file exists is provided below. IF EXIST

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial