I use Windows Subsystem Linux(Ubuntu 18.04) in my Win10, and I install a Maven in it. Besides, I install a maven in Win10 before. Now when I used mvn compile
in WSL, it told me that maven compile fail. I use which mvn
and find that it references to the Maven installed in Win10.
Besides, I run env
and find that Win10's Path is added to the WSL's Path. I don't want to use any thing in Win10's Path when I use WSL, how should I do?
To remove a distribution from WSL and delete all of the data associated with that Linux distribution, run wsl --unregister <distroName> where <distroName> is the name of your Linux distro, which can be seen from the list in the wsl -l command.
For Windows build LOWER than 17713: WSL uses WSL_DISTRIBUTION_FLAGS Enumeration to configure its behavior and interoperability between Windows and Linux side. Here is the code snippet from wslapi.h
header file.
/* Flags specifying WSL behavior */ typedef enum { WSL_DISTRIBUTION_FLAGS_NONE = 0x0, WSL_DISTRIBUTION_FLAGS_ENABLE_INTEROP = 0x1, WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH = 0x2, WSL_DISTRIBUTION_FLAGS_ENABLE_DRIVE_MOUNTING = 0x4 } WSL_DISTRIBUTION_FLAGS; #define WSL_DISTRIBUTION_FLAGS_VALID (WSL_DISTRIBUTION_FLAGS_ENABLE_INTEROP | WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH | WSL_DISTRIBUTION_FLAGS_ENABLE_DRIVE_MOUNTING) #define WSL_DISTRIBUTION_FLAGS_DEFAULT (WSL_DISTRIBUTION_FLAGS_ENABLE_INTEROP | WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH | WSL_DISTRIBUTION_FLAGS_ENABLE_DRIVE_MOUNTING)
At first launch, WSL uses the default flag = 0x7 (i.e. 0+1+2+4). If that flag = 0x5 (i.e. 0+1+4) Windows NT path will not appended in $PATH
environment variable. So, how to find that flags registry value? Open HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss
registry path in Registry Editor aka. regedit.exe
. Open each subkey with UID values and match DistributionName
with your installed distribution name. Then edit/add the Flags
DWORD registry value to 0x5
.
For Windows build HIGHER than 17713: In new build WSL uses wsl.conf
file to configure its behavior and interoperability between Windows and Linux side. That wsl.conf
file follows INI file format. Run wsl.exe
or bash.exe
. Create a file /etc/wsl.conf
. Then add the following interop section with any text editor in Linux.
[interop] enabled=false # enable launch of Windows binaries; default is true appendWindowsPath=false # append Windows path to $PATH variable; default is true
Save that file and exit from wsl.exe
. Now whenever WSL is executed Windows paths will not appended to Linux $PATH
environment variable.
As mentioned by AndrewBourgeois, you may need to shutdown the current instance of wsl with wsl --shutdown
or wsl -t <Distribution>
for changes to take effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With