How to remove the Win10's PATH from WSL

Sineatos picture Sineatos · Jul 14, 2018 · Viewed 8.3k times · Source

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?

Answer

Biswapriyo picture Biswapriyo · Jul 15, 2018
  • 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.