Skip to main content

Increase WSL memory

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:

  1. 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=26GB sets the maximum memory that WSL2 is allowed to use to 10 GB.
  2. >> "${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 to C:\Users\YourUsername.
    • \.wslconfig is the name of the configuration file for WSL. This file is used to configure various aspects of WSL, including memory allocation, CPU limits, etc.