Windows Subsystem for Linux (WSL) Setup Guide #
This guide explains step-by-step how to install and configure WSL on a Windows machine. WSL allows you to run Linux commands and tools in a Windows environment — especially useful for development and testing.
1. What is WSL? #
WSL is a feature that lets you run a full Linux distribution on Windows. There are two versions:
- WSL 1: Offers better compatibility between Windows and Linux.
- WSL 2: Includes a full Linux kernel and is faster and more efficient.
2. Installing WSL #
Step 1: Enable the WSL Feature #
-
Open PowerShell as Administrator
- Search for “PowerShell” in the Start menu, right-click, and select “Run as Administrator”.
-
Enable WSL and Install Default Distro (Ubuntu):
wsl --install
This command installs all required components and sets up Ubuntu as the default distro.
Step 2: Restart Your System #
- If prompted during the setup, restart your computer to complete the installation.
3. Setting WSL Version #
-
Set WSL 2 as the Default:
wsl --set-default-version 2
-
Check Installed WSL Versions:
wsl -l -v
💡 Required Windows Features: Only Windows Subsystem for Linux and Virtual Machine Platform are necessary. These can be enabled via Start > “Turn Windows features on or off”.
4. Installing Your Preferred Linux Distribution #
-
List Available Distributions:
wsl --list --online
-
Install a Specific Distro (e.g., Debian):
wsl --install -d Debian
-
Set Default Distro:
wsl --set-default <DistributionName>
5. Configuring the Linux Environment #
-
Launch the Linux Terminal:
- Open the terminal from Start Menu (e.g., type “Ubuntu” and hit Enter).
- On first launch, you’ll be asked to create a username and password.
-
Update the System:
sudo apt update && sudo apt upgrade -y
6. WSL Settings & Advanced Configuration #
Add Default Windows Path to Linux PATH #
To access Windows tools from your Linux terminal:
echo 'export PATH=$PATH:/mnt/c/Windows/System32' >> ~/.bashrc
source ~/.bashrc
Improve WSL 2 Disk Performance #
Create a ~/.wslconfig
file with custom settings:
[wsl2]
memory=4GB
processors=2
7. Useful WSL Commands #
Command | Description |
---|---|
wsl --list --online |
Lists available distributions. |
wsl --install -d <distro> |
Installs the specified Linux distribution. |
wsl --set-default-version 2 |
Sets WSL 2 as the default version. |
wsl --list --verbose |
Lists installed distros with version info. |
wsl --terminate <distro> |
Shuts down the specified distro. |
wsl --shutdown |
Shuts down all WSL instances and frees resources. |
8. Troubleshooting #
-
WSL 2 Error: “WSL 2 kernel component is missing” → Download and install the WSL 2 kernel update.
-
Performance Issues → Edit the
~/.wslconfig
file to allocate more CPU/RAM.
9. Sample Usage #
-
Launch WSL (e.g., Ubuntu):
- From the Start Menu, search for “Ubuntu” and open the terminal.
-
Create and Run a Simple Script:
echo 'echo "Hello, WSL!"' > hello.sh chmod +x hello.sh ./hello.sh
This guide covers WSL setup and basic configuration. Let me know if you need help customizing or extending your WSL environment! 😊