admin 管理员组

文章数量: 887019

Bash is the command-line interface for Linux distributions like Ubuntu, CentOS, Debian, Mint, Kali, RedHat, Fedora, etc. Bash provides a lot of different types of commands and tools to manage a Linux system. In this tutorial, we will learn how to install Bash on a Windows operating system like Windows 10.

Bash是Linux发行版的命令行界面,如Ubuntu,CentOS,Debian,Mint,Kali,RedHat,Fedora等。Bash提供了许多不同类型的命令和工具来管理Linux系统。 在本教程中,我们将学习如何在Windows 10等Windows操作系统上安装Bash。

什么是Bash? (What Is  Bash?)

Bash is the most popular shell or command line used in Linux distributions. Bash alternatives are Sh, KornShell, CShell, etc. Bash is the short form of the GNU Bourne-Again Shell and created in 1989 by the GNU supporter Free Software Foundation (FSF).

Bash是Linux发行版中最流行的shell或命令行。 Bash的替代品包括Sh,KornShell,CShell等。Bash是GNU Bourne-Again Shell的简称,由GNU支持者自由软件基金会(FSF)于1989年创建。

What Is  Bash?
什么是Bash?

Windows Linux子系统(WSL) (Windows Subsystem for Linux (WSL))

Containers are a new era of Virtualization where provides less resource usage and less complexity. Containers provide isolated environments for applications, processes, files, etc like a virtual system. Docker is the most known and popular containerization system. Windows also started full and complete container usage on Windows for Linux. It is called Windows Subsystem for Linux (WSL). This means the Linux operating system calls and standards are provided as a container on a Windows operating system. WSL is currently supported by the modern Windows operating systems like Windows 10 and Windows Server 2016 and 2019.

容器是虚拟化的新纪元,在此时代,资源使用量减少,复杂性降低。 容器为应用程序,进程,文件等(如虚拟系统)提供隔离的环境。 Docker是最著名和最受欢迎的容器化系统。 Windows还开始在Windows for Linux上完全使用和完全使用容器。 它称为Linux的Windows子系统(WSL)。 这意味着Linux操作系统调用和标准作为Windows操作系统上的容器提供。 当前,现代Windows操作系统(例如Windows 10和Windows Server 2016和2019)支持WSL。

Bash安装 (Bash Installation)

In order to install Bash on Windows, we will enable the WSL and download a Linux container image like Ubuntu, SUSE, etc from Microsoft store. Then we will run this container from the Windows command line MS-DOS or PowerShell.

为了在Windows上安装Bash,我们将启用WSL并从Microsoft商店下载Linux容器映像,例如Ubuntu,SUSE等。 然后,我们将从Windows命令行MS-DOS或PowerShell运行此容器。

为Linux启用Windows子系统 (Enable Windows Subsystem For Linux)

First, we will enable or install Windows Subsystem For Linux (WSL) with the PowerShell.  We need Administrative features enabled by running PowerShell from Start Menu where we will right-click and then select Run as administrator.

首先,我们将使用PowerShell启用或安装Linux的Windows子系统(WSL)。 我们需要通过从Start Menu运行PowerShell来启用Administrative功能,在该Start Menu上单击鼠标右键,然后选择Run as administrator

Enable Windows Subsystem For Linux
为Linux启用Windows子系统

We will run the following Enable-WindowsOptionalFeaturecommand in order to install and enable Microsoft-Windows-Subsystem-Linux feature.

我们将运行以下Enable-WindowsOptionalFeature命令以安装并启用Microsoft-Windows-Subsystem-Linux功能。

PS> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable Microsoft-Windows-Subsystem-Linux
启用Microsoft-Windows-子系统-Linux

We will be asked is we want to restart the computer after the installation is complete. We will answer Y.

系统将询问我们是否要在安装完成后重新启动计算机。 我们将回答Y

Restart The Computer
重新启动电脑

This will restart the system automatically in order to start the Windows with the WSL enabled.

为了启动启用了WSL的Windows,这将自动重新启动系统。

从Windows Store下载Linux映像/发行版 (Download Linux Image/Distributions From Windows Store)

In order to run bash, we have to download a Linux image/distributions which will provide the bash shell. Linux distributions can be downloaded from the Microsoft Store like below. We can access Microsoft Store from start menu with Microsoft Store keyword.

为了运行bash,我们必须下载将提供bash shellLinux映像/发行版。 可以从Microsoft Store下载Linux发行版,如下所示。 我们可以使用Microsoft Store关键字从开始菜单访问Microsoft Store。

Download Linux Image/Distributions From Windows Store
从Windows Store下载Linux映像/发行版

We will write linux to the search box and search. Alternatively, if we are looking for a specific Linux

我们将linux写入搜索框并进行搜索。 或者,如果我们正在寻找特定Linux

Search Linux Images
搜索Linux映像

The search results for the Linux container will be listed below. We can see that Linux distributions like Kali, Ubuntu, Debian, Suse, etc. The following information also provided with the search results.

Linux容器的搜索结果将在下面列出。 我们可以看到Linux发行版,例如Kali,Ubuntu,Debian,Suse等。以下信息也随搜索结果提供。

  • Popularity provides the count of the rating provided the given Linux distribution image.

    Popularity提供了给定Linux发行映像所提供的等级计数。

  • Rating is the provided points or starts for the given Linux distribution.

    Rating是给定Linux发行版提供的分数或起点。

  • Supported Systems shows which environments can run given Linux image like Computer, Phone, etc.

    Supported Systems显示了可以在给定Linux映像(例如计算机,电话等)下运行的环境。

  • Price is generally zero but used to show the price of the given Linux image.

    Price通常为零,但用于显示给定Linux映像的价格。

WSL Linux Images List
WSL Linux映像列表
WSL Ubuntu Image
WSL Ubuntu映像

We will select the  Linux distribution like Kali, Ubuntu, Debian, SUSE like below just click them. In this example, we will select the Ubuntu image with the latest version. Ubuntu 18.04 LTS can be downloaded for Lon Term Support.

我们将选择如下所示Linux发行版,如Kali,Ubuntu,Debian,SUSE,如下所示。 在此示例中,我们将选择最新版本的Ubuntu映像。 可以下载Ubuntu 18.04 LTS以获得长期支持。

WSL Ubuntu Image Download
WSL Ubuntu映像下载

During the download, the download status will be shown in the header like below. We can see that the Ubuntu image is about 221 MB and downloaded very fast.

在下载过程中,下载状态将显示在下面的标题中。 我们可以看到Ubuntu映像约为221 MB,并且下载速度非常快。

WSL Ubuntu Image Download
WSL Ubuntu映像下载

从Microsoft Store启动Bash(Launch Bash From Microsoft Store)

When the download is complete we can launch Ubuntu container from the Microsoft Store from the Launch button like below.

下载完成后,我们可以通过如下所示的“ Launch按钮从Microsoft Store启动Ubuntu容器。

Launch Ubuntu Container On Windows
在Windows上启动Ubuntu容器

We will see the following bash shell where it is initialized for the first run. As it says it may take a few minutes to see the shell.

我们将看到以下bash shell,其中该bash shell在首次运行时被初始化。 就像说的那样,可能需要几分钟才能看到外壳。

Ubuntu Shell
Ubuntu Shell

Before starting to use bash we will be asked some basic questions like the username and password which will set. In this example, we set the username ismail.  The password is not shown for security reasons. We see that the hostname part of the bash shell is the name of the computer which is DESKTOP-HQVAMA3 and the user name is ismail.

在开始使用bash之前,我们将被询问一些基本问题,例如将设置的用户名和密码。 在此示例中,我们将用户名设置为ismail 。 出于安全原因,未显示密码。 我们看到bash shell的主机名部分是计算机的名称,它是DESKTOP-HQVAMA3 ,用户名是ismail

Linux Bash Shell On Windows 10
Windows 10上Linux Bash Shell

从MS-DOS和PowerShell启动Bash (Start Bash From MS-DOS and PowerShell)

We can also start the Bash from the command line. MS-DOS or PowerShell can be used to start bash shell with the bash command like below.

我们也可以从命令行启动Bash。 可以使用MS-DOS或PowerShell通过如下所示的bash命令启动bash外壳。

> bash

OR

要么

PS> bash
Start Bash From MS-DOS
从MS-DOS启动Bash
Start Bash From PowerShell
从PowerShell启动Bash

在Windows上运行Bash命令 (Run Bash Commands On Windows)

We can run any Linux bash command on Windows like below. In this part, we will run commands like ping, uname , lsb-release.

我们可以在Windows上运行任何Linux bash命令,如下所示。 在这一部分中,我们将运行pingunamelsb-release类的命令。

$ whoami

$ ping poftut

$ uname -a

$ cat /etc/lsb-release
Run Bash Commands On Windows
在Windows上运行Bash命令

访问Windows驱动器C:\,D:\(Access Windows Drives C:\ , D:\)

After starting the bash on Windows we may need to access Windows partitions like C:\, D:\, and the users Documents and Settings folders. These partitions and folders are mounted in /mnt directory with their partition names. In this following example, we see the folders are listed in the C:\ partition.

在Windows上启动bash之后,我们可能需要访问Windows分区,例如C:\,D:\,以及用户的Documents and Settings文件夹。 这些分区和文件夹及其分区名称挂载在/mnt目录中。 在下面的示例中,我们看到文件夹在C:\分区中列出。

$ cd /mnt

$ cd c
Access Windows Drives C:\ , D:\
访问Windows驱动器C:\,D:\
LEARN MORE  How To Check If File Exists In Linux Bash? 了解更多如何检查Linux Bash中是否存在文件?

翻译自: https://www.poftut/how-to-download-and-install-linux-bash-shell-on-windows-10/

本文标签: 下载并安装 如何在 Windows shell Linux