The "No such file or directory" error when running bash on Windows typically occurs because the command is not found in your system PATH or the Windows Subsystem for Linux (WSL) distribution is corrupted. To fix this, verify that WSL is installed, ensure you are using the correct executable path like wsl.exe, and check for missing Linux binaries within your specific distribution.
Understanding the Root Cause
This error is distinct from a missing Windows application. When you type bash into the Windows Command Prompt or PowerShell, the operating system searches for an executable named bash.exe in your system's PATH environment variables. If WSL is installed but not configured correctly, or if the default distribution is missing its core files, Windows cannot locate the binary.
A common misconception is that bash.exe should exist in C:\Windows\System32. It does not. The Bash shell runs inside the Linux subsystem. Therefore, the error usually indicates that either the WSL feature is disabled, the default distribution failed to install properly, or you are attempting to run a legacy command without using the modern wsl.exe launcher.
Verifying WSL Installation Status
Before troubleshooting the specific file error, confirm that the underlying infrastructure is present. Open PowerShell as Administrator and run the following command:
wsl --list --verbose
If this command returns an error stating that WSL is not installed, or lists no distributions, the subsystem itself is missing. In this case, you must enable the feature via Settings > Apps > Optional Features > Add a Feature and search for "Windows Subsystem for Linux." Alternatively, run wsl --install in PowerShell to perform a default installation of Ubuntu and the necessary kernel components.
If the command works but shows a status of Stopped or Error, the distribution may be corrupted. You can try repairing it by uninstalling and reinstalling the specific distro using the Microsoft Store or by downloading the tarball directly from the vendor's GitHub repository.
Using the Correct Launch Commands
Modern versions of Windows 10 and 11 include wsl.exe as the primary interface for interacting with Linux distributions. Instead of typing bash, which relies on legacy compatibility layers that may be broken, use:
wsl
This command launches the default distribution defined in your WSL configuration. If you have multiple distributions installed, you can specify one explicitly:
wsl -d Ubuntu-20.04
If you specifically need the bash shell for scripting purposes and encounter the error, ensure you are calling it from within the WSL environment. Once inside WSL, simply typing bash will work because the Linux filesystem contains the actual /bin/bash binary. The error only persists when Windows tries to execute a Linux binary directly through the NTFS layer without the WSL bridge.
Checking Environment Variables and PATH
In rare cases where you have manually added WSL paths to your Windows environment variables, a typo or incorrect path can cause this issue. Check your System Environment Variables under Control Panel > System > Advanced System Settings > Environment Variables.
Look for any entries pointing to %LOCALAPPDATA%\Microsoft\WindowsApps. This folder often contains shims that redirect commands like bash.exe to WSL. If this path is missing or corrupted, Windows loses the ability to route the command. Reinstalling the Windows Terminal app from the Microsoft Store often repairs these shims automatically.
Additionally, if you are using a third-party terminal emulator, ensure it is not overriding the default behavior. For instance, some older versions of Git Bash or Cygwin might conflict with WSL integrations. Try launching the built-in Windows Terminal to isolate whether the issue is with the host application or the WSL installation itself.
Repairing Corrupted Distributions
If wsl --list --verbose shows a distribution but it fails to launch, the internal file system may be damaged. You can attempt a repair by exporting and re-importing the distribution, though this is complex. A simpler approach is to delete the corrupted instance and create a new one.
Run the following to unregister the broken distro:
wsl --unregister Ubuntu
Then, reinstall it via the Microsoft Store or by running wsl --install Ubuntu. This process recreates the necessary directory structure and installs fresh copies of core utilities like bash, ls, and apt.
For more complex issues involving logon sessions or update errors, refer to our guide on Can't Launch WSL: A Guide to Fixing Windows Subsystem for Linux Issues. If you are experiencing performance issues after repair, check out Slow moving folder with a lot of files from Windows to WSL to optimize file access speeds.
Frequently Asked Questions
Why does bash work in WSL but not in CMD?
Bash is a Linux executable located in the Linux filesystem, not the Windows NTFS partition. CMD cannot natively execute Linux binaries without the WSL translation layer. You must use the wsl command to bridge the gap between Windows and Linux environments.
How do I reset WSL handlers if they are broken?
There is no single command to reset handlers. The most effective method is to uninstall all WSL distributions using wsl --unregister and then reinstall them. This forces Windows to rebuild the registry keys and shim links associated with each distro.
Is bash.exe located in System32?
No. bash.exe does not exist in C:\Windows\System32. Any reference to it in that location is likely a shim or a leftover from a different toolchain. The actual binary resides inside the virtual hard disk of your WSL distribution.
What if I get a "Logon Session Not Found" error?
This error often accompanies WSL update failures. It suggests a mismatch between the Windows user session and the WSL service. Ensure your Windows account has administrative privileges and try restarting the computer to clear stale session tokens before attempting to launch WSL again.
Can I use PowerShell instead of CMD?
Yes. PowerShell supports the same wsl commands as CMD. In fact, PowerShell offers better integration with Windows features and is the recommended shell for managing WSL instances programmatically. The "No such file or directory" error will appear in PowerShell if the underlying WSL installation is missing.