How to remove the Win10's PATH from WSL

前端 未结 3 749
刺人心
刺人心 2020-12-25 13:25

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 i

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 14:06

    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

提交回复
热议问题