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

Rishav MishraRishav Mishra
2 min read

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.

  1. Download an official Ubuntu WSL image:

  2. 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

  1. Launch Ubuntu:

     wsl -d Ubuntu
    

    You’ll be logged in as root.

  2. Create a new user (replace yourname with your desired username):

     adduser yourname
    
    • Set a password & fill optional details.
  3. Grant sudo permissions:

     usermod -aG sudo yourname
    
  4. Set this user as default:

     echo -e "[user]\ndefault=yourname" >> /etc/wsl.conf
    
  5. Exit & restart WSL:

     exit
    
     wsl --terminate Ubuntu
     wsl -d Ubuntu
    

    Now you should log in as yourname automatically.

0
Subscribe to my newsletter

Read articles from Rishav Mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rishav Mishra
Rishav Mishra