Installing the Windows Subsystem for Linux (WSL)

WSL enables Windows computers to concurrently run Windows and Linux at the same time. Modern software development and deployment usually depends on Linux tools and commands. To be able to run a Linux container on a Windows workstation, we need the availability of the Linux Kernel.

To install Windows Subsystem for Linux (WSL)

To use the default Ubuntu distribution

  • Open a PowerShell terminal as Administrator and execute the command
    wsl --install

To install another distribution

  • Open a PowerShell terminal as Administrator and execute the command to get the list of available distributions
    wsl.exe --list --online
  • Install the desired distribution
    wsl --install -d MY_DISTRIBUTION_NAME

Create the Linux user

The installer will create a Linux user. By default it will use your Windows user name. Enter a password and retype it.

Create a default Unix user account: MY_USER_NAME
New password:
Retype new password:

Reboot the computer for the changes to take effect.

Configuration

Terminal

Install the Windows Terminal from the Microsoft App Store

Code editor

Configure Visual Studio Code to be able to access and debug in the Linux file system.

For more on this see Get started using Visual Studio Code with Windows Subsystem for Linux

Installation
  • Install Visual Studio Code on Windows, not in the WSL file system
Extensions

Remote Development extension pack

The installation will also install the following extensions

  • WSL
  • Dev Containers

Update the Linux distribution

In the Linux terminal execute

for OS update

sudo apt-get update

install wget and ca-certificates to be able to retrieve content from web servers

sudo apt-get install wget ca-certificates

Git

Install Git in WSL

Git is usually installed in the Linux distribution, update it to the latest version with

sudo apt-get install git
Configure Git in WSL
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
Install GitHub CLI in WSL
sudo apt install gh
Install the Git Credential Manager in WSL

Install the native Git credential manager in WSL

curl -sSL https://aka.ms/gcm/linux-install-source.sh | sudo bash
Install the Git Credential Manager in WSL
dotnet tool install -g git-credential-manager

IMPORTANT: For the change to take effect, close and open the WSL Linux terminal.

Verify the Git and Git Credential Manager installation in WSL
git --version; git credential-manager --version
Configure the Git Credential Manager in WSL
git-credential-manager configure
git config --global --replace-all  credential.hel
per "/mnt/c/Program Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe"
Line ending auto conversion

For more information on Git line ending auto conversion see Resolving Git line ending issues in WSL (resulting in many modified files)

Credential Provider in WSL

To set up the Credential Provider for the repository you use see credential.provider

Install Git in Windows

Download and install Git from Git for Windows

Install the GitHub CLI on Windows

In the terminal execute

winget install --id GitHub.cli

IMPORTANT: For the path changes to take effect close and re-open the terminal window, or close and re-open Visual Studio Code if you use the integrated terminal.

Share the credentials between the Windows and WSL Git instances

In Windows execute

 git config --global credential.helper wincred
Create GitHub personal access tokens

In the GitHub Web interface create new Personal Access Tokens, one for Windows and one for WSL with the following scopes

  • repo
  • workflow
  • read:org
Authenticate in GitHub in Windows
 gh auth login

For more information see Set up a WSL development environment

Leave a comment

Your email address will not be published. Required fields are marked *