WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Bug: Default $PATH missing system directories in WSL on Windows 11 24H2 WSL Version

Open jmaoito opened this issue 7 months ago • 5 comments

Windows Version

Microsoft Windows [Version 10.0.26100.4061]

WSL Version

2.4.13.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu 22.04

Other Software

Distro(s)

Ubuntu 22.04 (from Microsoft Store)

Debian (from Microsoft Store)

Repro Steps

When launching a fresh WSL session (especially via wsl -d Ubuntu-22.04 -e env or similar), the default PATH is incorrectly populated:

PATH=/usr/lib/wsl/lib:/mnt/c/Program Files/...:/mnt/c/WINDOWS:...

Expected Behavior

PATH should includes /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Actual Behavior

Missing from the front of PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

As a result, even basic commands like cat, grep, printenv, env, etc., do not work out of the box.

Diagnostic Logs

No response

jmaoito avatar May 21 '25 19:05 jmaoito

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

Once completed please upload the output files to this Github issue.

Click here for more info on logging If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

github-actions[bot] avatar May 21 '25 19:05 github-actions[bot]

Diagnostic information
Detected appx version: 2.4.13.0

github-actions[bot] avatar May 21 '25 19:05 github-actions[bot]

Hi @jmaoito! That is unexpected. Does this occur in both Debian and Ubuntu?

sirredbeard avatar May 21 '25 21:05 sirredbeard

Yes. I've tried Ubuntu, Ubuntu-22.04, Debian. All of them had the same problem. Ubuntu default even cannot go thru adding new user.

PS C:\Users\jmao> wsl --install -d Ubuntu Downloading: Ubuntu Installing: Ubuntu Distribution successfully installed. It can be launched via 'wsl.exe -d Ubuntu' PS C:\Users\jmao> wsl.exe -d Ubuntu Provisioning the new WSL instance This might take a while... Create a default Unix user account: jmao New password: Retype new password: passwd: password updated successfully Failed to create a regular user account OOBE command "/usr/lib/wsl/wsl-setup" failed, exiting

jmaoito avatar May 22 '25 14:05 jmaoito

@jmaoito: WSL doesn't directly control the Linux paths, those are controlled by /etc/login.defs, /etc/environment, your shell profiles and WSLENV. This is most likely caused by something in either of those.

One thing you can try is to run wsl bash -x which should make it easier to see where the $PATH is being changed.

OneBlue avatar May 27 '25 21:05 OneBlue

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue.

Thank you!

I have the same problem.

WslLogs-2025-06-04_14-22-19.zip

kingaj12 avatar Jun 04 '25 18:06 kingaj12