1st step - Disable Windows path on WSL
Option A: Add to wsl.conf (after Build 17093)
sudo nano /etc/wsl.conf
Then add
[interop]
appendWindowsPath = false
then
Ctrl+S
then Ctrl+X
then exit
.
Option B: remove paths on runtime
Add the following code to .bashrc
PATH=$(/usr/bin/printenv PATH | /usr/bin/perl -ne 'print join(":", grep { !/\/mnt\/[a-z]/ } split(/:/));')
Alternative (run once!):
echo "export PATH=`echo $PATH | tr ':' '\n' | grep -v /mnt/ | tr '\n' ':'`" >> ~/.bashrc
Alternative 2
Just add export PATH="$PATH:/usr/bin"
to the end of ~/.bashrc
, so that usr/bin
takes precedence over windows' apps. Probably not a good option.
Option C:
Edit Windows Registry. It is currently not recommended.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lxss\{GUID}\Flags
Change Flags
from 7
to 5
in order to exclude the WSL_DISTRIBUTION_FLAGS_APPEND_NT_PATH
enum.
2nd step - Restart WSL
Option A:
Simple reenter WSL and test:
echo $PATH
Option B:
Run at PowerShell as Admin:
Restart-Service LxssManager
Option C:
Terminating WSL from PowerShell as Admin using
wslconfig /t Ubuntu
Adapt was your need, Ubuntu-18.04
in my case
References:
https://github.com/microsoft/WSL/issues/1493
https://devblogs.microsoft.com/commandline/automatically-configuring-wsl
https://gist.github.com/ilbunilcho/4280bd55a10cefef75e74986b6bff936