27

I am trying to install the Windows Subsystem for Linux in my PC (Windows 10). I opened a "Command Prompt" window by running it as administrator and ran wsl --install without changing the initial default folder C:\Windows\system32. Thus, WSL is installed in this location by default.

Later, I uninstalled WSL by going to Settings -> Apps & Features -> Windows Subsystem for Linux Update -> Uninstall.

Then, I downloaded and installed WSL Update in C:\users\myaccount. However, when I run WSL from the start menu, it still goes to C:\Windows\system32.

Is there a way to move this default location of WSL installation to C:\users\myaccount. Besides, I have noticed that WSL is still in C:\Windows\system32 folder after I uninstall WSL from Settings -> Apps & Features.

NotTheDr01ds
  • 28,025
Ling
  • 693
  • 2
  • 7
  • 7

4 Answers4

40

It's important to understand that there are multiple components involved in a WSL installation, and whether you can "move" or change their installation location differs for each of those components:


tl;dr Most users are going to want to move the largest consumer of disk space - The WSL distribution itself. That is Item #5 below (read it for prerequisites), but short-version on the latest release:

wsl --manage <distro_name> --move <new_location>

Much more detail:

  1. The wsl.exe command, which is what you mainly appear to be asking about, is built-in to Windows in recent releases. You didn't (and can't) actually install or uninstall the actual wsl.exe through any of the Windows Features or Apps & Features settings. It is present when you install Windows.

  2. The base Windows Subsystem for Linux ("lxss", to some degree), which is also built into Windows as a "Windows Feature". As a Windows Feature, it can be enabled or disabled, but not, to my knowledge, uninstalled. As you can see in my post here, this takes up very little disk space.

  3. The WSL2 Virtual Machine Platform, which is also a Windows feature.

Like all other Windows features, no, you can't change the location where the files live. Most will be under System32. The fact that you were in that directory when you enabled the feature has nothing to do with it.

I can't recall which of the files in the C:\Windows\System32\lxss directory are there when Windows is installed.

The other components, which are not built-in to Windows, are:

  1. The WSL2 Linux kernel. This is actually what was removed when you uninstalled the "Windows Subsystem for Linux Update". I agree that it is confusingly named.

    This official kernel is also installed in a subdirectory with the other WSL binaries, in C:\Windows\System32\lxss\tools. While you can't change the folder where this kernel is installed, you can move it to another directory if you'd like and create a file in your Windows (not Linux) user profile directory named .wslconfig with the following contents:

    [wsl32]
    kernel="C:\path\to\kernel"
    

    You can also compile additional kernels and place them whereever you like, pointing to the one you want to launch in the .wslconfig.

  2. One or more WSL distributions.

    When you install a distribution using wsl --install -d <distro> or from the Microsoft Store, it is installed by default in %USERPROFILE%\AppData\Local\Packages\<PackageName>.

    These can be "moved" in one of two ways:

    • Latest releases

      As of WSL 2.3.11 (currently pre-release), WSL now includes a built-in command-line option to move a distribution to a new location:

      Assuming you are on the "App" version of WSL (most installations in the last 2 years), you can update with:

      wsl --update --pre-release
      

      You can then move any WSL2 (not WSL1) distribution using:

      wsl --manage <distro_name> --move <new_location>
      
    • Older releases

      On older releases, you can "move" distributions by exporting them and re-importing them.

      From PowerShell:

      mkdir D:\WSL\images # For example
      mkdir D:\WSL\instances\<newDistroName>
      cd D:\WSL
      

      wsl -l -v # Verify distro name to export wsl --export <distroname> .\images&lt;distroname>.tar wsl --import <newDistroName> .\instances&lt;newDistroName> .\images&lt;distroname>.tar wsl --set-default <newDistroName>

      You'll also need to set the default username in that copied instance via the /etc/wsl.conf file as discussed in this answer.

      It might also be possible to forcibly move the distribution files from your AppData folder to another location and then update the registry corresponding registry location (HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss). However, I have not tested this, nor seen anyone else try it. If you want to give it a shot, make sure you have a backup via wsl --export above.

NotTheDr01ds
  • 28,025
11

If changing the location of a specific distribution is the aim, this is probably the fastest and most secure way to do it :

  1. wsl --terminate distro_name
  2. move the ext4.vhdx file to new_location
  3. wsl --unregister distro_name
  4. wsl --import-in-place distro_name ext4.vhdx_file_in_new_location

all 4 operations are immediate.

cfeard
  • 129
9

This is the simplest to go about it

In case you want to move linux distributions installed under WSL, follow these steps :

Find out your Linux distribution through :

wsl -l

this will list all the distributions installed

Suppose Ubuntu is installed.

  1. Open windows settings
  2. Then open apps tab
  3. And then installed apps
  4. Your installed distribution (Ubuntu in our case) will be listed here
  5. Click on three-dot icon on the right side
  6. You'll get an option in the submenu "move", Click on it
  7. Move distribution to your desired location

PS: As others have already explained, you can't move a certain windows feature to another drive, In case you really want to move due to storage space concerns, you can change the location of windows installation itself, i.e by reinstalling windows

Chemist
  • 214
6

This can be down in powershell

# first install distro, check available distros:(fixed 2025/02/17)
wsl --list --online
# install e.g. Ubuntu-24.04
wsl --install -d Ubuntu-24.04

stop the running distro

wsl -t Ubuntu-24.04

export

wsl --export Ubuntu-24.04 "D:\ubuntu-ex.tar"

unregister the current one

wsl --unregister Ubuntu-24.04

make a directory in your new location

mkdir D:\WSL

import the exported to the new folder

wsl --import Ubuntu-24.04 "D:\WSL\ubuntu" "D:\ubuntu-ex.tar"

set it as default

wsl --set-default Ubuntu-24.04