您已经在Windows 11 或 Windows 10 上运行了适用于Linux的(Linux)Windows 子系统(Windows Subsystem)( WSL ),用于尝试一些 bash 命令,并且可能运行一些最好的 Linux 应用程序(best Linux apps)。这比使用双引导同时拥有两个操作系统要容易得多。
有些东西只在某些版本的WSL中有效,而且你不确定你有哪一个。因此,我们将向您展示如何在Windows 11和Windows 10上检查(Windows 10)WSL版本,以及其他一些技巧。
WSL 版本之间(Difference Between WSL Versions)有什么区别?
WSL只有两个版本;WSL 1和WSL 2。主要区别在于WSL 2具有完整的Linux 内核(Linux kernel),而WSL 1没有。将WSL 1视为WSL lite。如果您是忠实的Linux用户或认真学习Linux,请使用WSL 2。它作为一个完整的虚拟机运行,具有虚拟化带来的所有功能。WSL 2将提高文件系统性能并支持完整的系统调用兼容性。
WSL 2仅适用于Windows 11(Windows 11)或Windows 10版本 1903 (Version 1903) Build 19362或更高版本。如果您使用的是Windows 10并且一直保持最新状态,那就太好了。如果您不确定,我们有一篇文章可帮助您了解您拥有的 Windows 版本。(what version of Windows)旧版本的Windows 10仅与WSL 1兼容。
如何在Windows中检查(Windows)WSL 版本(WSL Version)
如果您在PowerShell中安装(PowerShell)WSL或使用(WSL)wsl.exe –install命令在命令行中安装 WSL,您将拥有WSL的默认版本。这意味着您拥有Ubuntu 20.04 LTS Linux发行版及其版本WSL 2。
假设(Suppose)您不确定是否安装了默认的WSL,或者您添加了几个不同的Linux发行版并且您想知道它们是什么版本。在这种情况下,这也很容易检查。
- 打开命令提示符(Command Prompt)或Powershell并运行命令wsl –list –verbose或wsl -l -v。
- 输出将发行版名称显示为NAME,无论它是在STATE下运行还是停止,以及WSL版本在VERSION下。注意星号。带有星号的WSL发行版是您的默认发行版。
这意味着如果您运行 WSL 而不告诉它使用哪个发行版,它将运行默认值。尝试查看默认发行版的命令行界面 ( CLI )。
如何更改 WSL 版本?
让我们将 openSUSE-42 从WSL 1更改为WSL 2。相同的方法可以将任何发行版从WSL 2更改为WSL 1。
- 打开命令提示符(Command Prompt)或PowerShell并运行以下命令:wsl –set-version [name] [wsl version number]其中 name 是发行版名称,wsl version number 是您想要的版本。在这种情况下,它是wsl –set-version openSUSE-42 2。
它将显示消息正在转换(Conversion),这可能需要几分钟......使用全新安装的发行版,可能只需 20 秒。当您收到消息时,它就完成了,转换(Conversion)完成。
- 要确保正确设置WSL版本,请再次运行wsl –list –verbose或wsl -l -v命令。
如何检查WSL 默认值(WSL Defaults)或上次更新(Update)?
在查看更改默认WSL版本或默认Linux发行版之前,您应该检查当前默认值是什么。这还将向您显示上次更新WSL的时间。
- 打开命令提示符(Command Prompt)或PowerShell并运行以下命令:wsl –status。
您将看到默认值、上次更新WSL的时间以及内核版本。
如何更新 WSL?
您检查了WSL的上次更新时间,已经有一段时间了。您想更新它以确保您拥有最新版本。
- 以管理员身份打开命令提示符(Command Prompt)或PowerShell 。通过在开始(Start)菜单中找到命令提示符(Command Prompt)或PowerShell来执行此操作,然后右键单击它并选择以管理员身份
运行。(Run)
- 运行命令wsl –update。如果有可用的更新,它将下载并安装。
- 更新完成后,此时您可以看到更新的内核版本。现在运行命令wsl –shutdown使更改生效。
如何获取WSL的自动更新?
您(Did)是否检查过您的WSL状态并看到显示“...由于您的系统设置而无法进行自动更新”的消息?这是解决此问题的方法。
- 打开Windows 设置(Windows Settings)并转到Windows 更新(Windows Update),然后转到高级(Advanced)选项。
- 打开接收(Receive)其他Microsoft产品的更新。现在您将始终拥有最新版本。
如何更改默认 WSL 版本(Default WSL Version)?
也许您只想为将来的Linux发行版安装WSL 1 。这很快就改变了。这也可用于将WSL 2设置为默认值。
- 打开命令提示符(Command Prompt)或PowerShell并运行以下命令:wsl –set-default-version [wsl 版本号](wsl –set-default-version [wsl version number])其中 wsl 版本号是您想要的版本。在此示例中,它是wsl –set-default-version 1。完成后,您将看到操作成功完成。
- 运行wsl –status命令以确认默认WSL版本已更改。
如何更改默认 Linux 发行版(Default Linux Distro)?
当您打开Windows 开始(Windows Start)菜单并选择WSL时,也许您想运行与Ubuntu不同的(Ubuntu)Linux发行版。没关系,很容易改变。
- 打开命令提示符(Command Prompt)或PowerShell并运行命令wsl –set-default [name],其中 name 是列表命令显示的发行版名称。在本例中,我们将其更改为 kali-linux。
- 更改只需一秒钟,命令提示符就会再次显示。使用wsl –list –verbose或wsl -l -v命令确认默认发行版已更改。
现在,当您从“开始(Start)”菜单运行 WSL 时,它会打开Kali Linux。
了解有关 WSL 命令的更多信息
要查看WSL(WSL)的内置帮助文档,请使用命令wsl –help。
此外,请查看我们关于在 Windows 11 上安装WSL和使用 bash(using bash on Windows 11)的文章。再次回来(Come),我们一定会为您提供更多与 WSL 相关的文章。
How to Check the Windows Subsystem for Linux (WSL) Version in Windows
You’ve got the Windows Subsystem for Linux (WSL) running on your Windows 11 or Windows 10 for trying some bash cоmmands, and maybe running some of the best Linux apps. It’s much easier than using a dual boot to have both operating systems.
Some things only work in certain versions of WSL though, and you’re not sure which one you have. So, we’ll show you how to check the WSL version on both Windows 11 and Windows 10, plus a few other tricks.
What’s the Difference Between WSL Versions?
There are only two versions of WSL; WSL 1 and WSL 2. The primary difference is that WSL 2 has the full Linux kernel whereas WSL 1 does not. Think of WSL 1 as WSL lite. If you’re a committed Linux user or serious about learning Linux, use WSL 2. It runs as a complete virtual machine with all the functionality that virtualization brings.WSL 2 will increase file system performance and supports full system call compatibility.
WSL 2 is available only on Windows 11 or Windows 10, Version 1903 Build 19362 or newer. If you’re on Windows 10 and you’ve been keeping it up to date, you’re good. If you’re unsure, we’ve got an article to help you find out what version of Windows you have. Older versions of Windows 10 only have compatibility with WSL 1.
How to Check WSL Version in Windows
If you install WSL in PowerShell or the command line using the wsl.exe –install command, you have the default version of WSL. That means you have the Ubuntu 20.04 LTS Linux distro and its version WSL 2.
Suppose you’re not sure you did the default WSL install, or you’ve added several different Linux distributions and you want to know what version they are. In that case, that’s easy to check too.
- Open the Command Prompt or Powershell and run the command wsl –list –verbose or wsl -l -v.
- The output shows the distro name as NAME, whether it’s running or stopped under STATE, and the WSL version under VERSION. Note the asterisk. The WSL distro with the asterisk is the default distro for you.
That means if you run WSL without telling it which distro to use, it will run the default. Try it to see the default distro’s command line interface (CLI).
How Can I Change the WSL Version?
Let’s change openSUSE-42 from WSL 1 to WSL 2. The same method works to change any distro from WSL 2 to WSL 1.
- Open the Command Prompt or PowerShell and run the following command: wsl –set-version [name] [wsl version number] where name is the distro name and wsl version number is the version you want. In this case, it is wsl –set-version openSUSE-42 2.
It will show the message Conversion in progress, this may take a few minutes… With a fresh install of the distro, it can take as little as 20 seconds. It’s done when you get the message, Conversion complete.
- To make sure you set the WSL version correctly, run the wsl –list –verbose or wsl -l -v command again.
How Can I Check the WSL Defaults or Last Update?
Before looking at changing the default WSL version or default Linux distro, you should check what the current defaults are. This will also show you the last time WSL was updated.
- Open the Command Prompt or PowerShell and run the following command: wsl –status.
You’ll see the defaults, the last time WSL was updated, as well as the kernel version.
How Do I Update WSL?
You checked the last update time for WSL and it’s been a while. You’d like to update it to make sure you have the latest version.
- Open the Command Prompt or PowerShell as administrator. Do this by finding Command Prompt or PowerShell in the Start menu, then right-click on it and select Run as administrator.
- Run the command wsl –update. If there’s an update available, it will download and install.
- Once the update finishes, you can see the updated kernel version at this point. Now run the command wsl –shutdown to make the change take effect.
How Can I Get Automatic Updates for WSL?
Did you check your WSL status and see the message that reads, “…automatic updates cannot occur due to your system settings.”? Here’s how to fix that.
- Open Windows Settings and go to Windows Update then Advanced options.
- Switch on Receive updates for other Microsoft products. Now you’ll always have the latest version.
How Can I Change the Default WSL Version?
Perhaps you want to only have WSL 1 for future Linux distro installs. That’s quickly changed. This can also be used to set WSL 2 as the default.
- Open the Command Prompt or PowerShell and run the following command: wsl –set-default-version [wsl version number] where wsl version number is the version you want. In this example, it is wsl –set-default-version 1. You’ll see the operation completed successfully when it’s done.
- Run the wsl –status command to confirm the default WSL version has changed.
How Can I Change the Default Linux Distro?
Maybe you want to run a different Linux distro than Ubuntu when you open the Windows Start menu and select WSL. That’s ok, it’s easy to change.
- Open the Command Prompt or PowerShell and run the command wsl –set-default [name], where name is the distro name as shown by the list command. In this example, let’s change it to kali-linux.
- It only takes a second for the change to happen and the command prompt to show again. Use the wsl –list –verbose or wsl -l -v command to confirm the default distro has changed.
Now when you run WSL from the Start menu, it opens Kali Linux.
Learn More About the WSL Commands
To see the built-in help docs for WSL, use the command wsl –help.
Also, check out our articles on installing WSL and using bash on Windows 11. Come back again and we’ll surely have more WSL-related articles for you.