Windows 10 및 가상 머신의 Linux 배포판에서 WSL을 어떻게 설정하고 사용합니까?

Windows 10 및 가상 머신의 Linux 배포판에서 WSL을 어떻게 설정하고 사용합니까?

Windows 10에 WSL 2를 설치했습니다. Debian 시스템이 있습니다. 모든 것이 잘 작동합니다.

PowerShell 터미널에서 WSL을 시작하고 싶기 때문에 명령을 입력합니다 wsl. 오류가 발생합니다.

PS C:\Users\MyUser> wsl
wsl : The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wsl
+ ~~~
    + CategoryInfo          : ObjectNotFound: (wsl:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

왜 그런 겁니까?

업데이트 이상하게도 명령을 받으려고 하면 부정적인 대답이 나옵니다.

PS C:\WINDOWS\system32> Get-Command wsl -All
Get-Command : The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Command wsl -All
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (wsl:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

그래도 실행 파일 은 에 wsl.exe있어야 C:\Windows\Syste32합니다.

다음을 사용하여 별칭을 설정하는 경우:

Set-Alias -Name wsl -Value C:\Windows\system32\wsl.exe

실행해도 출력에는 아무런 변화가 없습니다 wsl(동일한 오류가 발생함).

Windows 사양:

  • 에디션 Windows 10 Pro
  • 버전 2004
  • OS 빌드 19041.572
PS C:\WINDOWS\system32> Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux


FeatureName      : Microsoft-Windows-Subsystem-Linux
DisplayName      : Windows Subsystem for Linux
Description      : Provides services and environments for running native user-mode Linux shells and tools on Windows.
RestartRequired  : Possible
State            : Enabled
CustomProperties :
                   ServerComponent\Description : Provides services and environments for running native user-mode Linux shells and
                   tools on Windows.
                   ServerComponent\DisplayName : Windows Subsystem for Linux
                   ServerComponent\Id : 1033
                   ServerComponent\Type : Feature
                   ServerComponent\UniqueName : Microsoft-Windows-Subsystem-Linux
                   ServerComponent\Deploys\Update\Name : Microsoft-Windows-Subsystem-Linux

답변1

명령 이후

wslconfig.exe /l

응답으로 준

Windows Subsystem for Linux Distributions:
docker-desktop-data
docker-desktop
Debian

기본값이 설정되어 있지 않은 것으로 나타났습니다. 따라서 저는 간단히 기본값을 설정했습니다.

wslconfig.exe /setdefault "Debian"

이제 wslconfig.exe /l나는 다음을 얻습니다:

Windows Subsystem for Linux Distributions:
Debian (Default)
docker-desktop-data
docker-desktop

를 사용하여 WSL 2 기본 배포판을 시작할 수 있습니다 wsl.

답변2

이것은 실제로 Powershell 코드 질문이 아니라 '가상 머신에서 Windows 10 및 Linux 배포판에서 WSL을 어떻게 설정하고 사용합니까?'에 대한 질문입니다.

WSL은 서비스입니다 ...

https://docs.microsoft.com/en-us/windows/wsl/install-win10

... Windows 10에서 Linux 배포판을 실행할 수 있습니다. PowerShell에서 실행하는 앱/명령이 아닙니다. 따라서 해당 오류는 매우 구체적입니다. 배포판이 실행 중이어야 합니다!

동영상에 표시된 대로 필요한 단계를 검토하고 활용하셨나요?

...WSL을 구성하려면...

(Get-CimInstance -ClassName CIM_OperatingSystem).Version
# Results
<#
10.0.19041
#>


$PSVersionTable
# Results
<#
Name                           Value
----                           -----
PSVersion                      5.1.19041.546
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.19041.546}
BuildVersion                   10.0.19041.546
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
#>

# Results
<#
Get-Command -Name wsl.exe

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     wsl.exe                                            10.0.19... C:\WINDOWS\system32\wsl.exe
#>

Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
# Results
<#
FeatureName      : Microsoft-Windows-Subsystem-Linux
DisplayName      : Windows Subsystem for Linux
Description      : Provides services and environments for running native user-mode Linux shells and tools on Windows.
RestartRequired  : Possible
State            : Enabled
CustomProperties :
                   ServerComponent\Description : Provides services and environments for running native user-mode Linux shells and tools on
                   Windows.
                   ServerComponent\DisplayName : Windows Subsystem for Linux
                   ServerComponent\Id : 1033
                   ServerComponent\Type : Feature
                   ServerComponent\UniqueName : Microsoft-Windows-Subsystem-Linux
                   ServerComponent\Deploys\Update\Name : Microsoft-Windows-Subsystem-Linux
#>

...그리고 해당 Linux 배포판을 사용하도록 구성된 배포판도 있습니다.

wsl --list --verbose
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

관련 정보