Windows Subsystem for Linux
There is used currently Windows 10 1903 according to Windows update history records. My first recommendation is to upgrade to currently latest Windows 10 which is Windows 10 2004 using the Microsoft page Download Windows 10 if that is possible. There have been lots of improvements on Windows Subsystem for Linux (WSL) like introducing Windows Subsystem for Linux 2 as it can be read for example on Wikipedia page Windows 10 version history for Version 2004 (May 2020 Update). The Windows Developer Mode should be disabled before starting the Windows 10 upgrade.
Cause of the error
The error is caused by starting 32-bit Windows command processor in %SystemRoot%\SysWOW64\cmd.exe
instead of 64-bit version in %SystemRoot%\System\cmd.exe
. For that reason the Windows File System Redirector is active when 32-bit Windows command processor takes C:\Windows\System32
from local environment variable PATH
to search for a file with name bash
with a file extension as defined in local environment variable PATEXT
resulting in searching in directory C:\Windows\SysWOW64
for bash
. But there is no bash.exe
in Windows system directory for 32-bit applications. Therefore no bash.exe
is found by 32-bit cmd.exe
.
Please read on Stack Overflow What is the reason for "X is not recognized as an internal or external command, operable program or batch file"? for more details about how cmd.exe
uses PATH
and PATHEXT
and how these two very important environment variables can be configured by a user.
Solution 1: Using 64-bit Windows command processor
The first solution is opening a 64-bit command prompt by starting %SystemRoot%\System\cmd.exe
instead of %SystemRoot%\SysWOW64\cmd.exe
on 64-bit Windows.
This is definitely the best and easiest to achieve solution.
Solution 2: Run BASH with full qualified file name
The second solution is running bash
from within 32-bit command prompt window with full qualified file name using the special alias Sysnative
which means typing C:\Windows\Sysnative\bash.exe
instead of just bash
.
See also the Microsoft documentation Naming Files, Paths, and Namespaces.
This is definitely the best solution on using already the 32-bit Windows environment.
Solution 3: Hard link to bash.exe
Attention: This solution is not recommended for long time usage!
The third solution is starting %SystemRoot%\SysWOW64\cmd.exe
as administrator with clicking with secondary (right) mouse button on this file in Windows File Explorer and clicking on context menu item Run as administrator to explicitly start 32-bit Windows command processor with elevated privileges of local administrator.
Next enter following command line:
mklink /H %SystemRoot%\SysWOW64\bash.exe %SystemRoot%\Sysnative\bash.exe
That creates a hard link with name bash.exe
in directory %SystemRoot%\SysWOW64
to file bash.exe
in %SystemRoot%\Sysnative
. Then 32-bit cmd.exe
can find a file bash.exe
in %SystemRoot%\SysWOW64
which results in execution of %SystemRoot%\System32\bash.exe
in Windows system directory for 64-bit applications.
Run in command prompt window mklink /?
for help on this command or read even better SS64 documentation of MKLINK.
Note: It is advisable to delete that hard link with del %SystemRoot%\SysWOW64\bash.exe
executed in a command prompt window opened with Run as administrator before doing a Windows update or Windows upgrade which updates %SystemRoot%\System32\bash.exe
and recreate the hard link after newer bash.exe
is installed by the Windows update/upgrade.
I don't recommend using this solution as it could cause easily troubles in future.
Solution 4: Creation of bash.cmd
Attention: This solution is not recommended for compatibility with batch files containing bash
!
The fourth solution is starting %SystemRoot%\SysWOW64\cmd.exe
as administrator with clicking with secondary (right) mouse button on this file in Windows File Explorer and clicking on context menu item Run as administrator to explicitly start 32-bit Windows command processor with elevated privileges of local administrator.
Next enter following command line:
echo @%SystemRoot%\Sysnative\bash.exe %*>%SystemRoot%\SysWOW64\bash.cmd
That command line creates with Windows installed into C:\Windows
the batch file C:\Windows\SysWOW64\bash.cmd
with the single command line:
@C:\Windows\Sysnative\bash.exe %*
So 32-bit cmd.exe
finds now on entering just bash
in a 32-bit Windows command prompt window the file bash.cmd
in %SystemRoot%\SysWOW64
on using directory path C:\Windows\System32
in local environment variable PATH
redirected by file system redirector to C:\Windows\SysWOW64
. The batch file runs C:\Windows\System32\bash.exe
with all parameters specified on starting bash.cmd
passed to bash.exe
.
Note: A Windows batch file containing just bash
executed by 32-bit Windows command processor results in starting bash.exe
via bash.cmd
, but then no more command lines in batch file are executed by cmd.exe
because of Windows command processor ends batch file execution on finishing execution of bash.cmd
executed without usage of command CALL from initially executed batch file. So this solution is not safe to use for batch files containing just the file name bash
executed by 32-bit cmd.exe
.
I don't recommend using this solution as it could cause troubles with batch files.
Conclusion
There are definitely even more solutions, but best is running 64-bit Windows command processor on 64-bit Windows to have unrestricted access to all executables ported from Linux and installed by default with Windows 10 like bash.exe
or the executables in directory %SystemRoot%\System32\OpenSSH
which exist also only as 64-bit executables.
Best Answer
To install Windows Subsystem Linux, you have to enable Developer Mode in Settings App. So open Settings > Update & Security > For Developer > Developer Mode & select it to enable.
Or you may enable Developer Mode with registry tweak. Make registry script (.reg) with the following::
Then wait some time to download the developer package. Next, open the Control Panel, click “Programs”, and click “Turn Windows Features On or Off” under Programs and Features. Enable the “Windows Subsystem for Linux (Beta)” option in the list here and click “OK”. Alternatively install WSL with commands::
Command Prompt:
Powershell:
Then resrtart your system and you are good to go. From Windows 10 build 16215, it is no longer required to enable Developer Mode and beta tag was removed from WSL optional component. See Windows 10 Installation Guide for further details.