Skip to content

Instantly share code, notes, and snippets.

@sanyer
Last active August 25, 2022 23:14
Show Gist options
  • Save sanyer/399dd0c3ff304a8e765ca489fa93daa4 to your computer and use it in GitHub Desktop.
Save sanyer/399dd0c3ff304a8e765ca489fa93daa4 to your computer and use it in GitHub Desktop.
Install WSL without Windows Store
# Windows now supports a simple WSL installation using the command:
wsl --install
$ErrorActionPreference = 'Continue'
$ProgressPreference = 'SilentlyContinue'
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform
Set-Location -Path "$env:TEMP"
Invoke-WebRequest -Uri 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi' -OutFile 'wsl_update_x64.msi' -UseBasicParsing
Start-Process 'msiexec.exe' -Wait -ArgumentList '/I wsl_update_x64.msi /quiet'
Remove-Item -Path 'wsl_update_x64.msi'
wsl --set-default-version 2
$ErrorActionPreference = 'Continue'
$ProgressPreference = 'SilentlyContinue'
$WslDistName = 'ubuntu2204'
$WslDistFullName = 'Ubuntu-22.04'
$WslDistUrl = 'https://aka.ms/wslubuntu2204'
$WslDistExe = 'ubuntu2204.exe'
$WslParentDir = 'C:\Tools'
$WslDistPath = Join-Path -Path $WslParentDir -ChildPath $WslDistName
Set-Location -Path $WslParentDir
wsl --set-default-version 2
Invoke-WebRequest -Uri "$WslDistUrl" -OutFile "$WslDistName.appx" -UseBasicParsing
Rename-Item -Path "$WslDistName.appx" -NewName "$WslDistName.zip"
Expand-Archive -Path "$WslDistName.zip" -DestinationPath "$WslDistName"
Remove-Item -Path "$WslDistName.zip"
$userenv = [System.Environment]::GetEnvironmentVariable("PATH", "User")
[System.Environment]::SetEnvironmentVariable("PATH", "$userenv;$WslDistPath", "User")
Start-Process "cmd.exe" -Wait -ArgumentList "echo /c $(Join-Path -Path "$WslDistPath" -ChildPath "$WslDistExe")"
wsl --set-version $WslDistFullName 2
wsl --list --verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment