wsl -- shutdown
Open PS and do the following. [These are two lines]
Write-Output "[wsl2]
memory=10GB" >> "${env:USERPROFILE}\.wslconfig"
# to see
Get-Content "${env:USERPROFILE}\.wslconfig"
To see total memory:
top
htop
free -h
Components of the command:
Write-Output "[wsl2] memory=26GB":- This writes the string
[wsl2] memory=10GB. [You must write [wsl2] in one line and memory=10GB in another line] [wsl2]indicates that the settings being configured are for WSL2, which is the second version of WSL with better performance and more advanced features.memory=26GBsets the maximum memory that WSL2 is allowed to use to 10 GB.
- This writes the string
>> "${env:USERPROFILE}\.wslconfig":>>is the append operator, which adds the output to the specified file, instead of overwriting it. If the file doesn't exist, it will create one.${env:USERPROFILE}is a PowerShell expression that references the current user's profile directory. For most users, this will resolve toC:\Users\YourUsername.\.wslconfigis the name of the configuration file for WSL. This file is used to configure various aspects of WSL, including memory allocation, CPU limits, etc.