Install WSL 2 On Windows 10 Using PowerShell Command Line

Enable WSL 2

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

Enable ‘Virtual Machine Platform’ 

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Set WSL 2 as default

wsl --set-default-version 2

Install a Linux distro

Choose your distro. Simply use one of these URLs:

# Go to a folder where you would like to download the distro
cd <somefolder>

# Download Ubuntu 20.04
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing

# install downloaded *.appx file
Add-AppxPackage .\Ubuntu.appx

Either execute in command prompt

PS E:\distro\ubunu> ubuntu2004.exe

Or open from widows search

wsl --list --verbos
 
NAME                   STATE           VERSION
Ubuntu-20.04           Running         1
wsl --list --all

Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)

Convert Ubuntu on WSL 1 to WSL 2

wsl --set-version Ubuntu-20.04 2

Open wsl

Restart WSL

Restart-Service LxssManager

or

wsl --terminate [YourDistroName]
wsl --shutdown

Work in VSCode

Open Remote window

server being installed

If you get the following error

The user has not been granted the requested logon type at this computer

Then execute the following

Restart-Service vmcompute

References

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s