Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Essential Commands for Managing WSL Environments

Tech Aug 16 19

Enabling Required Windows Features

Before using WSL, the subsystem and virtual machine platform must be activated.

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

Installing and Updating WSL

WSL can be set up using the --install flag, and updated to the latest version with --update.

wsl --install
wsl --update

Setting the WSL Default Version

Switching the default version to WSL 2 ensures better performance and full system call compatibility.

wsl --set-default-version 2

Checking WSL Status and Version Information

Review the current state of WSL and the installed client version.

wsl --status
wsl --version

Working with Individual Distributions

Start a specific distribution by name.

wsl -d <DistributionName>

End a session within a distribution using exit or logout.

exit

View all installed distributions along with their WSL version and running status.

wsl --list --verbose
# or the short form:
wsl -l -v

Managing Distribution Lifecycles

List distributions available from the online store.

wsl --list --online

Install a new distribution by specifying its name.

wsl --install -d <DistributionName>

Set a distribution as the default target for wsl commands (example with Ubuntu 22.04).

wsl --set-default Ubuntu-22.04

Remove a distribution completely.

wsl --unregister <DistributionName>

Shutting Down WSL

Terminate all running WSL instances and the background VM.

wsl --shutdown

Relocating a Distribution to a Different Drive

Moving a WSL 2 instance to another location involves exoprting, unregistering, and importing.

  1. Verify the target distribution exists with wsl -l -v.
  2. Export the distribution to a tar file (example with Ubuntu 22.04).
    wsl --export Ubuntu-22.04 D:\Envs\wsl\ubuntu-22.04.tar
    
  3. Unregister the original instance.
    wsl --unregister Ubuntu-22.04
    
  4. Import the tar file into a new location, specifying WSL 2.
    wsl --import Ubuntu-22.04 D:\Envs\wsl\ubuntu-22.04 D:\Envs\wsl\ubuntu-22.04.tar --version 2
    
  5. Launch the relocated instance.

Integrating with Visual Studio Code

With the WSL extension installed in VS Code, open any directory inside a WSL distribution by executing code . from the Linux shell. VS Code will automatically connect to that WSL instance.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.