setting up WSL2

a step-by-step guide to installing WSL2 on Windows 11 Home Edition

This tutorial describes how to set up WSL2 (Windows Subsystem for Linux) on Windows 11 Home Edition as in September 2024. The guide is adapted and consolidated from several online resources.

Check these blogs (in Chinese):

  1. Windows 11 搭建 WSL2 运行环境(2024)- CSDN博客 https://blog.csdn.net/qq_39316962/article/details/139927197
  2. 为什么Win11找不到Hyper-V?怎么解决?https://www.abackup.com/enterprise-backup/win11-cannot-find-hyper-v-6540.html

1. Enable Virtualization and Required Features

1.1 Install Hyper-V (Windows 11 Home Only)

Windows 11 Professional users can skip this step.

  1. Create a file named win11-home-hyperv.bat
  2. Add the following content:
    pushd "%~dp0"
    dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
    for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
    del hyper-v.txt
    Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL
    
  3. Right-click the file and run as Administrator.

1.2 Enable Windows Features

  1. Open Control Panel
  2. Go to Programs → Turn Windows features on or off
  3. Enable:
    • Hyper-V
    • Windows Subsystem for Linux
    • Virtual Machine Platform
  4. Click OK and restart your computer.

2. Install WSL2

2.1 Open PowerShell or Command Prompt

Check available WSL commands:

wsl --help

2.2 Update WSL and Set Default Version

wsl --update
wsl --set-default-version 2

2.3 List Available Linux Distributions

wsl --list --online
wsl --install -d Ubuntu-22.04

By default, Linux will be installed on the system drive (C:).

2.5 Move Ubuntu to Another Drive (Optional)

If your C: drive has limited space, you can migrate the distribution. Here we move Ubuntu-22.04 to D: drive and rename it to Ubuntu-22.04-D.

2.5.1: Check and Stop Running Distributions

wsl -l -v
wsl --terminate Ubuntu-22.04

2.5.2: Export the Distribution

wsl --export Ubuntu-22.04 D:\ubuntu2204-export.tar

2.5.3: Unregister the Original Distribution

wsl --unregister Ubuntu-22.04

2.5.4: Import to a New Location

wsl --import Ubuntu-22.04-D D:\Ubuntu-22.04 D:\ubuntu2204-export.tar --version 2

After completion:

3. Configure Proxy Networking (Optional)

If you need proxy access:

3.1 Install Clash

Install Clash and enable:

3.2 Configure .wslconfig

Create a file:

C:\Users\<your-username>\.wslconfig

Add:

[experimental]
autoMemoryReclaim=gradual
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

3.3 Close WSL

wsl --shutdown

3.4 Test Connection

Start a new WSL and test connection:

wget www.google.com

If successful, your proxy configuration is working correctly.

Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • installing Psi4 and Forte
  • cluster witout internet connection
  • installing CentOS 6 on a cluster node
  • writing scientific papers
  • tutorials for quantum chemistry