Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
940 views
in Technique[技术] by (71.8m points)

linux - How to remove the Win10's PATH from WSL

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • 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 HKCUSoftwareMicrosoftWindowsCurrentVersionLxss 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...