## Create .wslconfig in C:/Users/youruser
[wsl2]
memory=3GB # Limits VM memory in WSL 2 up to 3GB
processors=4 # Makes the WSL 2 VM use four virtual processors
[wsl2]
# https://docs.microsoft.com/en-us/windows/wsl/wsl-config (Docs)
# https://github.com/microsoft/WSL/issues/4166 (Topic)
memory=4GB
swap=16GB
localhostForwarding=true
# turn off all wsl instances such as docker-desktop
wsl --shutdown
notepad "$env:USERPROFILE/.wslconfig"
# .wslconfig
[wsl2]
memory=3GB # Limits VM memory in WSL 2 up to 3GB
processors=4 # Makes the WSL 2 VM use two virtual processors
Stored in your %UserProfile% directory.
Used to configure settings globally across all installed Linux distributions running as the WSL 2 version.
Can be used only for distributions run by WSL 2. Distributions running as WSL 1 will not be affected by this configuration as they are not running as a virtual machine.
To get to your %UserProfile% directory, in PowerShell, use cd ~ to access your home directory (which is typically your user profile, C:Users<UserName>) or you can open Windows File Explorer and enter %UserProfile% in the address bar. The directory path should look something like: C:Users<UserName>.wslconfig.