Install Linux on Windows with WSL2 (使用 WSL2 在 Windows 上安装 Linux)

Install Linux on Windows with WSL2 (使用 WSL2 在 Windows 上安装 Linux)

https://learn.microsoft.com/en-us/windows/wsl/

在 Windows 上运行 Linux - 在 Windows 11 上运行 Ubuntu 20.04 LTS

Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.
开发人员可以在 Windows 计算机上同时访问 Windows 和 Linux 的强大功能。 通过适用于 Linux 的 Windows 子系统 (WSL),开发人员可以安装 Linux 发行版 (例如 Ubuntu、OpenSUSE、Kali、Debian、Arch Linux 等),并直接在 Windows 上使用 Linux 应用程序、实用程序和 Bash 命令行工具,不用进行任何修改,也无需承担传统虚拟机或双启动设置的费用。

1. Windows 11 系统设置

1.1 Check requirements for running WSL 2 (检查运行 WSL 2 的要求)

To update to WSL 2, you had better to run Windows 11.

To check your version and build number, select Windows logo key + R, type winver, select OK.
若要检查 Windows 版本及内部版本号,选择 Windows 徽标键 + R,然后键入 winver,选择 OK

在这里插入图片描述

在 Windows 命令提示符下输入 ver 命令。

Microsoft Windows [版本 10.0.22621.1265]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cheng>ver

Microsoft Windows [版本 10.0.22621.1265]

C:\Users\cheng>

1.2 Enable the Windows Subsystem for Linux (启用适用于 Linux 的 Windows 子系统)

You must first enable the “Windows Subsystem for Linux” optional feature before installing any Linux distributions on Windows.
需要先启用 [适用于 Linux 的 Windows 子系统] 可选功能,然后才能在 Windows 上安装 Linux。

1.3 Enable Virtual Machine feature (启用虚拟机功能)

Before installing WSL 2, you must enable the Virtual Machine Platform optional feature. Your machine will require virtualization capabilities to use this feature.
安装 WSL 2 之前,必须启用 [虚拟机平台] 可选功能。计算机需要虚拟化功能才能使用此功能。

  1. 开始 -> 设置 -> 应用 -> 可选功能

在这里插入图片描述

  1. 可选功能 -> 更多 Windows 功能

在这里插入图片描述

  1. 勾选 [适用于 Linux 的 Windows 子系统] 和 [虚拟机平台]

在这里插入图片描述

  1. Wait to restart your machine and move on to the next step.
    请等待重新启动计算机,然后继续执行下一步。

2. WSL 命令无法 - 解析服务器的名称或地址

Microsoft Windows [版本 10.0.22621.1105]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cheng>wsl --list --online
无法解析服务器的名称或地址

C:\Users\cheng>
  1. 开始 -> 设置 -> 网络和 Internet -> WLAN -> 属性

在这里插入图片描述

  1. DNS 服务器分配

手动 + 首选 DNS: 114.114.114.114
在这里插入图片描述

Microsoft Windows [版本 10.0.22621.1105]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cheng>wsl --list --online
以下是可安装的有效分发的列表。
请使用“wsl --install -d <分发>”安装。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_8_5                        Oracle Linux 8.5
OracleLinux_7_9                        Oracle Linux 7.9
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
openSUSE-Leap-15.4                     openSUSE Leap 15.4
openSUSE-Tumbleweed                    openSUSE Tumbleweed

C:\Users\cheng>

3. Download the Linux kernel update package (下载 Linux 内核更新包)

  1. Download the latest package: WSL2 Linux kernel update package for x64 machines https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

wsl_update_x64.msi

在这里插入图片描述

  1. Run the update package downloaded in the previous step. (Double-click to run - you will be prompted for elevated permissions, select ‘yes’ to approve this installation.)
    运行上一步中下载的更新包。(双击以运行 - 系统将提示你提供提升的权限,选择 yes 以批准此安装。)

Once the installation is complete, move on to the next step - setting WSL 2 as your default version when installing new Linux distributions. (Skip this step if you want your new Linux installs to be set to WSL 1).
安装完成后,请继续执行下一步 - 在安装新的 Linux 分发时,将 WSL 2 设置为默认版本。(如果希望将新的 Linux 安装设置为 WSL 1,请跳过此步骤。)

4. Set WSL 2 as your default version (将 WSL 2 设置为默认版本)

Open PowerShell and run this command to set WSL 2 as the default version when installing a new Linux distribution:
在安装新的 Linux 发行版时运行以下命令,将 WSL 2 设置为默认版本:

Microsoft Windows [版本 10.0.22621.1105]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cheng>wsl --set-default-version 2
有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
操作成功完成。

C:\Users\cheng>

5. Change the default Linux distribution installed (更改默认安装的 Linux 发行版)

By default, the installed Linux distribution will be Ubuntu. This can be changed using the -d flag.
默认情况下,安装的 Linux 分发版为 Ubuntu。 可以使用 -d 标志进行更改。

To change the distribution installed, enter: wsl --install -d <Distribution Name>. Replace <Distribution Name> with the name of the distribution you would like to install.
若要更改安装的发行版,请输入:wsl --install -d <Distribution Name>。 将 <Distribution Name> 替换为要安装的发行版的名称。

To see a list of available Linux distributions available for download through the online store, enter: wsl --list --online or wsl -l -o.
若要查看可通过在线商店下载的可用 Linux 发行版列表,请输入:wsl --list --onlinewsl -l -o

To install additional Linux distributions after the initial install, you may also use the command: wsl --install -d <Distribution Name>.
若要在初始安装后安装其他 Linux 发行版,还可使用命令:wsl --install -d <Distribution Name>

Please try running wsl --list --online to see a list of available distros and run wsl --install -d <DistroName> to install a distro.
请尝试运行 wsl --list --online 以查看可用发行版列表并运行 wsl --install -d <DistroName> 以安装发行版。

Microsoft Windows [版本 10.0.22621.1105]
(c) Microsoft Corporation。保留所有权利。

C:\Users\cheng>wsl --list --online
以下是可安装的有效分发的列表。
请使用“wsl --install -d <分发>”安装。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
OracleLinux_8_5                        Oracle Linux 8.5
OracleLinux_7_9                        Oracle Linux 7.9
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
openSUSE-Leap-15.4                     openSUSE Leap 15.4
openSUSE-Tumbleweed                    openSUSE Tumbleweed

C:\Users\cheng>
C:\Users\cheng>wsl --install -d Ubuntu-20.04
正在安装: Ubuntu 20.04 LTS
已安装 Ubuntu 20.04 LTS。
正在启动 Ubuntu 20.04 LTS…

C:\Users\cheng>

在这里插入图片描述

文件夹目录
在这里插入图片描述

6. bash 启动

6.1 WIN + R -> cmd -> bash

在这里插入图片描述

在这里插入图片描述

6.2 WIN + R -> bash

在这里插入图片描述

在这里插入图片描述

7. 任务栏启动

Ubuntu 20.04 on Windows 固定到任务栏
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

使用 exit 退出环境。

8. Ubuntu 20.04 LTS 保存位置

AppData 默认是隐藏的。
在这里插入图片描述

C:\Users\cheng\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState

在这里插入图片描述

References

https://yongqiang.blog.csdn.net/
https://learn.microsoft.com/en-us/windows/wsl/install-manual

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/129044790