Installing Windows Subsystem For Linux 2 Wsl2
Author: Stu FeeserStu Feeser with Alta3 Research explains the process of installing Windows Subsystem for Linux 2 (WSL2)
Windows Subsystem for Linux 2 (WSL2) is a fast and efficient development platform that blows away WSL1. The older WSL1 is painfully slow for certain tasks. With WSL2 installed, you’ll have a complete ubuntu 20.04 system running on your Windows 10 machine, which performs like you are directly connected to a bare metal ubuntu server. We’ll use WSL2 for running other demonstrations in this series.
Objectives:
- Install WSL2
- Why WSL1 is not preferred
Tasks:
-
Make sure you are running the lastest Windows 10. Use the cmd.exe executable by pressing your Windows key and then typing in cmd to open up your cmd terminal. Then run
ver
inside the cmd terminal. You should see the following version or later:Microsoft Windows [Version 10.0.19042.804] (c) 2020 Microsoft Corporation. All rights reserved. C:\Users\maxwellsmart>ver Microsoft Windows [Version 10.0.19042.804] #<------------- GOOD, THIS VERSION SUPPORTS WSL2
-
If you do NOT see the current version as shown above, then stop to upgrade to Windows 10. See you in about 20 minutes!
`Settings` ▸ `Update & Security` ▸ `Windows Update` ▸ `Install now`
-
Repeat the above, rebooting, installing, rebooting, installing, and rebooting and installing until your ancient OS is current! This is worth it!
-
If you have already installed WSL, you may have the old version. Check your current version. If it is VERSION 1, you have the OLD version. You want version 2.
PS C:\Users\maxwellsmart>
wsl -l -v
NAME STATE VERSION * Ubuntu Running 1 #<------------- BUMMER, VERSION 1 (UPDATE REQUIRED)
Why is this relevant?
WSL1 is based on Microsoft’s Linux-compatible kernel interface, a compatibility translation layer with no Linux kernel code.
WSL2 is redesigned with a Linux kernel running in a lightweight VM environment, and innovators have found a lot more things they can do with WSL2. -
Open Windows PowerShell Run as an Administrator. Enter the command below windows DISM commands
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Download and install the Linux kernel update package as per this documentation.
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
-
You are going to reboot next, so this would be a great time to change your PC’s hostname. Most likely, your hostname is something like
3DGh23d-dell-eekzonk
which creates a horrible hostname on the linux command line as WSL adopts your Windows 10 hostname as the WSL2 hostname. Normally we always edit out hostname to be something generic likehostname
or justhost
.Settings
▸System
▸About
▸Rename this PC
If you are a course developer, changing your hostname to
host
will mean NEVER editing your hostname again. When you copy and paste your commands into the lab steps, your hostname will behost
. -
REBOOT
-
Set WSL2 as default. Open Windows PowerShell Run as an Administrator. Enter this command. It takes about five minutes to complete.
wsl --set-default-version 2
-
Install ubuntu 20.04 on your Windows Subsystem for Linux (WSL2). Click Here.
a. Click Install
b. Click the X on the popup window so you don’t have to sign in.You will not be using this application directly! We’re only allowing ubuntu to be opened in the Windows terminal.
-
When an ubuntu terminal pops up, you will be prompted for a user name and password. Consider a generic username like user as your username.
username"
user`Why do this?
Because your linux prompt will now beuser@host
which is akin to John Belushi’s COLLEGE shirt, and will speed up your course writing since no edits are necessary from screen shots!