Installing MSFT Store WSL Distros to a custom location
Tags: wsl, wsl2, windows, windowssubsystemlinu
Published: 2021-01-06 15:17:00

If you are running out of space on your C drive and want to keep your DEV environment and tools in a separate location for some reason, follow this guide.

By default the Linux distributions installed from the Microsoft Store are available in the same place as other Windows store apps (%USERPROFILE%\AppData\Local\Packages\).

#Grab the .appx package file:
To download the .appx package of a distro directly, run the following in PowerShell:

```
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing
```
This will download Ubuntu 20.04 distro and save it under the name *“Ubuntu.appx”*

*Available Distros*:

> Ubuntu 20.04 - https://aka.ms/wslubuntu2004
Ubuntu 20.04 ARM - https://aka.ms/wslubuntu2004arm
Ubuntu 18.04 - https://aka.ms/wsl-ubuntu-1804
Ubuntu 18.04 ARM - https://aka.ms/wsl-ubuntu-1804-arm
Ubuntu 16.04 - https://aka.ms/wsl-ubuntu-1604
Debian GNU/Linux - https://aka.ms/wsl-debian-gnulinux
Kali Linux - https://aka.ms/wsl-kali-linux-new
OpenSUSE Leap 42 - https://aka.ms/wsl-opensuse-42
SLES - https://aka.ms/wsl-sles-12

#Unpack the distro:
Navigate to the directory and extract the package. Extract to a folder that has full access permission.
You can unzip the downloaded package using any archiver of your choice, or you can simply do it via PowerShell itself:
```
move .\Ubuntu.appx .\Ubuntu.zip
Expand-Archive .\Ubuntu.zip
```
#Initializing
In the unzipped folder there’s an EXE file (according to the name of the distribution)

![Folder](https://miro.medium.com/max/503/1*A7KQ4R3YJwHp3Jq9rRGNAQ.jpeg)
######  Based on the version of Linux distro you are using, the executable name can be different.

Now, run the executable to start initializing…
This will extract the “rootfs” and Register the WSL.

**NOTE:** You can register with a different name using wsl --import and perform multiple installs :)
```
wsl.exe --import <DistributionName> <InstallLocation> <FileName>
```
Eg:
```
wsl.exe --import Debian1 D:\Deb1 .\install.tar.gz
```
Wait till the process completes and you’ll be prompted to create a new user account and rest of the process follows accordingly.

![Img2](https://miro.medium.com/max/700/0*2Iaae3f_ZBbMHUfL.png)

After the installation is complete, you’ll find the “rootfs” folder is created which has all the libraries, executables etc…

![Img3](https://miro.medium.com/max/264/1*kQXIMs7vdWTaLIMbObY_Sw.jpeg)

To verify installation use `wsl --list --all` or `wsl -l --all` to list names of installed or imported WSL distros.

![Img4](https://miro.medium.com/max/530/1*1xS2QjWZXCKjMRW7gz1qHw.png)

#Adding to PATH
You’ll have to use the distribution launcher application in target folder every time to run your distro. So, additionally you can add your distro path to PATH environment variable to invoke it from anywhere.
```
$userenv = [System.Environment]::GetEnvironmentVariable(“Path”, “User”) [System.Environment]::SetEnvironmentVariable(“PATH”, $userenv + “;D:\DebianWSL”, “User”)
```

#Useful Links:
* [Manually download Windows Subsystem for Linux distro packages](https://docs.microsoft.com/en-us/windows/wsl/user-support?redirectedfrom=MSDN)