Blog
Linux inside Windows: The Complete Guide to WSL2 for Developers
1. Beginner Level: Installation and Fundamentals
Before you begin, ensure that virtualization is enabled in your BIOS/UEFI (usually labeled as “Virtualization Technology” or “SVM”).
Installation (The Express Method)
Open PowerShell as an Administrator and enter the following command:
wsl --install
Note: A system restart is required after the process finishes. The system will automatically install the Ubuntu distribution by default.
User Configuration
- Launch the Ubuntu app from the Start menu.
- Set your Username and Password (characters will not appear as you type).
- Update the system packages:
sudo apt update && sudo apt upgrade -y
2. Intermediate Level: Environment and Tools
Windows Terminal
Install Windows Terminal from the Microsoft Store. It supports tabs, custom profiles, and allows you to switch seamlessly between PowerShell and the Linux console.
VS Code Integration
This is the most crucial step for any developer:
- Install VS Code on Windows.
- Inside VS Code, install the extension named “WSL”.
- In your Ubuntu terminal, type
code .– the editor will open in Windows but will operate directly on the Linux file system.
Docker Desktop in WSL2
Docker in WSL2 doesn’t require a heavy virtual machine:
- Download and install Docker Desktop for Windows.
- In settings (Settings > General), ensure “Use the WSL 2 based engine” is checked.
- In (Settings > Resources > WSL Integration), enable integration for your Ubuntu distribution.
3. Advanced Level: Optimization and Tuning
Resource Management (.wslconfig)
By default, WSL2 can consume a lot of RAM. To limit this, create a file in Windows at: C:\Users\YourName\.wslconfig and add the following:
[wsl2]
memory=8GB # Max RAM for WSL
processors=4 # Number of CPU cores
guiApplications=true
Enabling Systemd
To manage services (e.g., systemctl start apache2), create a file inside Linux:
sudo nano /etc/wsl.conf
Add this content:
[boot]
systemd=true
Shell Personalization (ZSH)
Instead of the default Bash, install ZSH with Oh My Zsh for better productivity:
sudo apt install zsh -y
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
4. Expert: Troubleshooting and Backup
The File System Performance Rule
Golden Rule: Keep your project files inside the WSL file system (e.g.,
/home/user/projects). Working on Windows files (via the/mnt/c/...path) is drastically slower.
Reclaiming Disk Space
The WSL virtual disk (.vhdx) does not shrink automatically. Occasionally, use the diskpart tool on Windows:
# In PowerShell:
wsl --shutdown
diskpart
select vdisk file="C:\Path\To\Your\Disk\ext4.vhdx"
compact vdisk
Environment Backup
You can export your entire environment to a single file to move it to another computer:
wsl --export Ubuntu my_ubuntu_backup.tar
Congratulations! Your WSL2 environment is now fully optimized for professional development work.
