我正在关注此处的教程:https://www.youtube.com/watch?v =ZMfHaUkhfc0 我大约在 15:00 左右。我已在管理员帐户的 PowerShell 中安装了 WSL2。我以普通用户身份登录。我安装了 Docker Desktop 和 Ubuntu。我重新启动。然后我再次以管理员帐户打开 Powershell,但它没有看到我安装的 Ubuntu 发行版或我安装的 Docker Desktop。
PS C:\windows\system32> wsl -l -v
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
PS C:\windows\system32> wsl.exe -d Ubuntu
There is no distribution with the supplied name.
PS C:\windows\system32> wsl.exe --install Ubuntu
Copyright (c) Microsoft Corporation. All rights reserved.
Usage: wsl.exe [Argument] [Options...] [CommandLine]
Arguments for running Linux binaries:
If no command line is provided, wsl.exe launches the default shell.
--exec, -e <CommandLine>
Execute the specified command without using the default Linux shell.
--
Pass the remaining command line as is.
同样,我使用常规(非管理员)帐户,并且能够在 Windows 中打开 Ubuntu 应用程序和 Docker 桌面应用程序,但我以管理员身份运行的 Powershell 会话也看不到。我该如何解决?为什么wsl.exe --install Ubuntu
调用失败并显示简单的使用消息?
使用 WSL 安装的 Linux 发行版是按用户安装,不能与其他 Windows 用户帐户共享(参考https://learn.microsoft.com/en-us/windows/wsl/setup/environment)。
因此,通过以管理员帐户运行 powershell,您将不会看到使用常规(非管理员)帐户安装的发行版。相反,我希望您通过
wsl -l -v
使用常规用户 powershell 会话运行来看到它们。可能由管理员 powershell 会话运行的命令
wsl.exe --install Ubuntu
会向您显示帮助,因为您没有使用管理员帐户安装任何发行版。在这种情况下,由于安装了 wsl(显然,因为您必须是管理员才能安装它),但没有分发(因为您使用普通用户安装了它们),所以它会向您显示帮助(参考 1)。https://learn.microsoft.com/en-us/windows/wsl/install)。您应该运行该命令
wsl --list --online
,然后运行wsl --install -d <DistroName>
.