如何从 WSL 中删除 Win10 的 PATH [英] How to remove the Win10's PATH from WSL
问题描述
我在 Win10 中使用 Windows 子系统 Linux(Ubuntu 18.04),并在其中安装了 Maven.另外,我之前在Win10中安装了一个maven.现在,当我在 WSL 中使用 mvn compile
时,它告诉我 maven 编译失败.我使用which mvn
发现它引用了Win10中安装的Maven.
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.
另外,我运行env
,发现WSL的Path中添加了Win10的Path.用WSL的时候不想用Win10的Path里面的东西,怎么办?
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?
推荐答案
对于低于 17713 的 Windows 版本:WSL 使用 WSL_DISTRIBUTION_FLAGS 枚举 来配置其行为以及 Windows 和 Linux 端之间的互操作性.这是来自
wslapi.h
头文件的代码片段.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)
首次启动时,WSL 使用默认标志 = 0x7(即 0+1+2+4).如果该标志 = 0x5(即 0+1+4)Windows NT 路径将不会附加到
$PATH
环境变量中.那么,如何找到标志注册表值呢?在注册表编辑器中打开HKCUSoftwareMicrosoftWindowsCurrentVersionLxss
注册表路径.regedit.exe
.使用 UID 值打开每个子项,并将DistributionName
与您安装的分发名称匹配.然后将Flags
DWORD 注册表值编辑/添加到0x5
.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? OpenHKCUSoftwareMicrosoftWindowsCurrentVersionLxss
registry path in Registry Editor aka.regedit.exe
. Open each subkey with UID values and matchDistributionName
with your installed distribution name. Then edit/add theFlags
DWORD registry value to0x5
.对于 Windows 版本 高于 17713:在新版本中 WSL 使用
wsl.conf
文件 来配置它的行为和 Windows 和 Linux 端之间的互操作性.该wsl.conf
文件遵循 INI 文件格式.运行wsl.exe
或bash.exe
.创建文件/etc/wsl.conf
.然后添加以下 interop 部分以及任何文本Linux 中的编辑器.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. Thatwsl.conf
file follows INI file format. Runwsl.exe
orbash.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
保存该文件并从
wsl.exe
退出.现在,无论何时执行 WSL,Windows 路径都不会附加到 Linux$PATH
环境变量中.Save that file and exit from
wsl.exe
. Now whenever WSL is executed Windows paths will not appended to Linux$PATH
environment variable.如 AndrewBourgeois 所述,您可能需要使用
wsl --shutdown
或wsl -t
关闭 wsl 的当前实例以使更改生效.As mentioned by AndrewBourgeois, you may need to shutdown the current instance of wsl with
wsl --shutdown
orwsl -t <Distribution>
for changes to take effect.这篇关于如何从 WSL 中删除 Win10 的 PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!