Sep 13, 2021

Public workspaceInstall WSL and VSCode on Windows 10

  • 1University of Arizona
Icon indicating open access to content
QR code linking to this content
Protocol CitationKenneth Schackart 2021. Install WSL and VSCode on Windows 10 . protocols.io https://dx.doi.org/10.17504/protocols.io.bx63prgn
License: This is an open access protocol distributed under the terms of the Creative Commons Attribution License,  which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited
Protocol status: Working
We use this protocol and it’s working
Created: September 13, 2021
Last Modified: September 13, 2021
Protocol Integer ID: 53179
Keywords: windows 10, install wsl, install wsl2, install ubuntu, VS Code wsl,
Abstract
This protocol describes how to install Ubuntu, WSL, and connect to WSL with VS Code on Windows 10. By the end you should have a working version of Ubuntu and WSL. VS Code will be able to work with your Ubuntu installation. You will also have Python3 since Ubuntu comes packaged with it.

Most of the information presented here is given in the attached Microsoft Docs link.
Image Attribution
lewing@isc.tamu.edu Larry Ewing
Guidelines
This protocol only pertains to machines running Windows 10. Your results may vary for other Windows operating systems.
Materials
Windows 10 machine
Safety warnings
Getting WSL and Python running smoothly on windows can be frustrating, take a break before you want to beak something.
Before start
To update to WSL 2, you must be running Windows 10.
  • For x64 systems: Version 1903 or higher, with Build 18362 or higher.
  • For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.
  • Builds lower than 18362 do not support WSL 2. Use the Windows Update Assistant to update your version of Windows.
To check your version and build number, select Windows logo key + R, type winver, select OK. Update to the latest Windows version in the Settings menu.
Enable WSL
Enable WSL
Open Windows Powershell as Administrator.
Note
To run as Administrator, you can hit the Windows key, search for powershell, and on the right select "Run as Administrator". This allows you to make changes to your system.

In Powershell, enter the following command to enable WSL:

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

In Powershell, enter the following to enable virtualization:

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

Restart your machine to make the changes take effect.
Download the Linux kernel update package:


Run the package.
Set WSL2 as Default
Set WSL2 as Default
Open Powershell as administrator and run:

wsl --set-default-version 2

Install Ubuntu
Install Ubuntu
Go to the Microsoft Store and install a version of Ubuntu.
Note
Hit Windows key, type "Store", select Microsoft Store. Search for Ubuntu. Installing a version that ends with LTS means it is Long term stable. I recommend one of those versions.

Check Installation
Check Installation
Open Ubuntu by hitting the Windows key, and type "Ubuntu", and open it.

If an Ubuntu window opens but is quickly closed, continue to the next step.

If Ubuntu opens properly, go to step 13 to set up VS Code.

If WSL has failed to open by briefly flashing and then closing, it means your machine is still blocking virtualization. This must be resolved by entering BIOS. How to do this varies by laptop type. It will generally involve shutting the machine off, powering it on, and while it boots you need to hit a certain key to pause boot up.

Search the web for "How to enter BIOS <insert computer name here>"

You will not be able to see this protocol in BIOS, so open this page on another device.
Once in BIOS, use the arrow keys to navigate the menus and search for any settings regarding "virtualization" and enable them.

This may be something like "Virtualization Technology".
Note
Refer to the menu at the bottom of the BIOS screen for instructions on how to navigate, change settings, and save changes.

Save the changes you have made to the BIOS settings and restart.
Check Installation Again
Check Installation Again
Try starting Ubuntu again.

If it still gets closed, hit the Windows key, type features, and select "Turn Windows features on or off". If there is the feature "Windows Hypervisor Platform", enable that. Also make sure that "Virtual Machine Platform" and "Windows Subsystem for Linux" are enabled.
Set up VS Code
Set up VS Code
Install Visual Studio Code.


Open it once installed.
Open the Extensions tab by clicking on the icon with 4 squares (3 together, 1 detached).
Screen capture of sidebar, with Extensions highlighted

Search for "Remote - WSL" and install it. You will now have a green square in the bottom left corner of VS Code. This is how you access WSL from VS Code.
Displaying no current remote connection

Click the green square in the bottom left corner.
Under the search bar at the top a few options will be displayed. Select "New WSL window"
Remote options menu, with first option highlighted to open new WSL window
You can then close the old window.
Now VS Code is accessing your WSL instance. The bottom left corner should now look something like this:

Displaying active remote connection to WSL Ubuntu

Update
Update
From the top menu, select Terminal -> New Terminal
In the new terminal run the following to update


sudo apt-get update

You should now have a working version of WSL and access to it through VS Code.

Some things to keep in mind:
  • You can see if your current VS Code session is running in WSL by looking at the green rectangle at the bottom left corner

  • Since WSL has its own file system, if you plan to interact with GitHub using SSH keys, you will need to generate new ones using the WSL terminal, and add them to your GitHub

  • Whatever repositories you want to run in WSL should be cloned using the WSL terminal

  • WSL can be run without VS Code to have a nice linux terminal