WSL移除PATH中Windows共享的位置

以下运行环境为Windows 10 1909 18363.592,理论上1809之后的版本都通用

WSL默认启动后查看PATH变量内容如下:
在这里插入图片描述
可以看到大量/mnt/c开头的位置,这些都是从Windows系统的PATH变量中合并过来的,这样就容易出现在WSL中如果有和Windows中相同名称的命令,可能会出现调用紊乱,下面记录一下如何让WSL保持自己PATH变量的纯洁性~

$ sudo vim /etc/wsl.conf

这个wsl.conf文件默认是不存在的,直接编辑内容如下:

# 不加载Windows中的PATH内容
[interop]
appendWindowsPath = false

# 不自动挂载Windows系统所有磁盘分区
[automount]
enabled = false

保存退出后关闭WSL,再重新运行WSL,发现并没有卵用?然后在Github上找到了这个Issue

In 1903 we made a change to keep distribuitons running for a while after your last client exits. You could have hit this in 1809, but the Windows was very small. You’d also hit this if you launched something in the background (keeping the distro alive).
Work-around is to manually terminate your distro after modifying /etc/wsl.conf using:
wsl.exe --terminate <distro_name>

好吧~开个cmd执行下面命令:

wsl --list
# 适用于 Linux 的 Windows 子系统:
# Ubuntu-18.04 (默认)
wsl --terminate Ubuntu-18.04

再启动WSL,OJBK了~
在这里插入图片描述

wsl.conf微软官方完整文档:
https://devblogs.microsoft.com/commandline/automatically-configuring-wsl/

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DexterLien

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值