¿Cómo configuro y uso WSL en Windows 10 y una distribución de Linux en una máquina virtual?

¿Cómo configuro y uso WSL en Windows 10 y una distribución de Linux en una máquina virtual?

Instalé WSL 2 en mi Windows 10. Tengo un sistema Debian. Las cosas funcionan bien.

Quiero iniciar WSL desde una terminal PowerShell, así que escribo el comando wsl. Recibo el error:

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

¿Porqué es eso?

Actualizar Por extraño que parezca, cuando intento obtener el comando, obtengo una respuesta negativa:

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

Aún así, el ejecutable wsl.exeestá en C:\Windows\Syste32donde debería estar...

Si configuro un alias con:

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

nada cambia en la salida cuando ejecuto wsl(me sale el mismo error).

Detalles de Windows:

  • Edición Windows 10 Pro
  • Versión 2004
  • Compilación del sistema operativo 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

Respuesta1

desde el comando

wslconfig.exe /l

dio como respuesta

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

Noté que el valor predeterminado no estaba configurado. Por lo tanto, simplemente configuro el valor predeterminado:

wslconfig.exe /setdefault "Debian"

Ahora con wslconfig.exe /lobtengo:

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

y puedo iniciar la distribución predeterminada de WSL 2 con wsl.

Respuesta2

En realidad, esta no es una pregunta sobre el código de Powershell, sino "¿Cómo configuro y uso WSL en Windows 10 y una distribución de Linux en una máquina virtual?"

WSL es un servicio...

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

... permitiendo que las distribuciones de Linux se ejecuten en Windows 10. No es una aplicación/comando para ejecutar desde PowerShell. Entonces, ese error es bastante específico. ¡Tu distribución debe estar ejecutándose!

¿Ha revisado y aprovechado los pasos necesarios como se muestran en los videos...?

...para configurar 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
#>

...y su distribución configurada para usar esa distribución de 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

información relacionada