How to Install WSL at a Custom Location and Set Up Default User

If you're using Windows Subsystem for Linux (WSL) and want to:
✅ Install a WSL distribution (like Ubuntu) in a custom location (e.g., D:\wsl\ubuntu
)
✅ Fix the missing username/password setup (common with manual imports)
✅ Set a default user so you don’t log in as root
This guide will walk you through the process step by step.
Why Install WSL in a Custom Location?
By default, WSL installs distributions in C:\Users\<user>\AppData\Local\Packages
. If you:
Have limited space on
C:
Prefer organizing WSL on another drive (e.g.,
D:\wsl
)Want better disk performance
Manual installation (wsl --import
) is the solution—but it skips the initial username/password setup, requiring extra steps.
Step 1: Download a WSL Distro (Ubuntu)
You need a rootfs (Linux filesystem) .tar.gz
file.
Download an official Ubuntu WSL image:
Choose
ubuntu-jammy-wsl-amd64-ubuntu22.04lts.rootfs.tar.gz
Save it somewhere accessible (e.g.,
C:\Users\YourName\Downloads
).
Step 2: Install WSL at a Custom Location
Open PowerShell (Admin) and run:
wsl --import Ubuntu D:\wsl\ubuntu C:\Users\YourName\Downloads\ubuntu-jammy-wsl-amd64-ubuntu22.04lts.rootfs.tar.gz
Ubuntu
: The distro name (can be changed).D:\wsl\ubuntu
: The custom install location..tar.gz
: Path to the downloaded Ubuntu image.
✅ Verify installation:
wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
Step 3: Fix Missing Username/Password Setup
Since wsl --import
skips user setup, you’ll log in as root
. Let’s fix that.
Option 1: Set Default User via wsl.conf
Launch Ubuntu:
wsl -d Ubuntu
You’ll be logged in as
root
.Create a new user (replace
yourname
with your desired username):adduser yourname
- Set a password & fill optional details.
Grant sudo permissions:
usermod -aG sudo yourname
Set this user as default:
echo -e "[user]\ndefault=yourname" >> /etc/wsl.conf
Exit & restart WSL:
exit
wsl --terminate Ubuntu wsl -d Ubuntu
Now you should log in as
yourname
automatically.
Subscribe to my newsletter
Read articles from Rishav Mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
