3 echo "Installing WSL 2 (Windows Subsystem for Linux with Hyper-V) ..."
5 echo "Security: requires administrator approval to install"
7 IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
9 $MYPWD = (Get-Item .).FullName
10 & curl.exe -fA "MS" -o "$Env:TEMP\install-wsl2.ps1" "$Env:WEBI_HOST/packages/wsl2/install-wsl2.ps1"
11 powershell -Command "Start-Process cmd -Wait -Verb RunAs -ArgumentList '/c cd /d %CD% && powershell -ExecutionPolicy Bypass $Env:TEMP\install-wsl2.ps1'"
13 # From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/
14 Function Test-CommandExists
17 $oldPreference = $ErrorActionPreference
18 $ErrorActionPreference = 'stop'
19 try {if(Get-Command $command){RETURN $true}}
21 Finally {$ErrorActionPreference=$oldPreference}
24 IF(!(Test-CommandExists wsl))
29 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
31 echo "!!! READ CAREFULLY !!!"
33 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
35 echo "WSL 2 was NOT installed yet. You MUST follow these instructions:"
37 echo " 1. REBOOT you computer to finish the WSL 1 install"
38 echo " (either click Start Menu => Restart, or run 'shutdown /r /t 5')"
40 echo " 2. RE-RUN this WSL 2 installer"
41 echo " (WSL 2 cannot finish installing until the WSL 1 install is complete)"
43 echo " 3. Download and Install Linux"
44 echo " (see https://webinstall.dev/wsl2)"
53 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
55 echo "!!! READ CAREFULLY !!!"
57 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
59 echo "WSL 2 is now installed, HOWEVER, you MUST:"
61 echo "However, you still MUST INSTALL LINUX:"
63 echo " 1. Download and Install Ubuntu Linux"
64 echo " (see https://webinstall.dev/wsl2)"
66 echo " 2. Set WSL to use WSL 2 with Hyper-V. For example:"
67 echo " wsl.exe --set-version Ubuntu-20.04 2"
68 echo " wsl.exe --set-default-version 2"