在WSL 2中,PATH变量经常被重置。如何修复这个问题?

huangapple go评论77阅读模式
英文:

PATH-variable in wsl 2 gets always reset . How to fix that?

问题

在我重置Ubuntu(wsl2)后,无法设置例如:

export PATH=$PATH:/usr/local/go/bin

我的意思是它设置了,但是在我关闭终端后,所有配置都被重置,我应该执行:

export PATH=$PATH:/usr/local/go/bin

再次强调,即使我完全删除wls和ubuntu并重新安装,但没有任何变化。

英文:

after I reset Ubuntu (wsl2) from apps I can't set, for example,
> export PATH=$PATH:/usr/local/go/bin

I mean it set, but after I closed the terminal all config got reset and I should
> export PATH=$PATH: /usr/local/go/bin

Again, even I remove wls and ubuntu completely and reinstall, but nothing change

答案1

得分: 13

首先,这是大多数shell的预期行为。在你的bash shell中,导出的变量只在会话期间保留。你需要将export命令添加到你的~/.bashrc文件中。每次打开shell时,该文件都会被源化。

你可以运行echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc将该命令添加到bashrc文件中,或者使用你选择的编辑器。添加了export命令后,运行source ~/.bashrc或重新启动你的shell。

此后,Go应该可用。

如果你有一个需要添加到源路径的Python模块安装路径,这也适用。

英文:

First, this is the expected behavior of most shells. In your bash shell, the exported variables are only kept for a session. You need to add the export command to your ~/.bashrc file. The file is sourced every time you open the shell.

You can run echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc to add the command to the bashrc file, or use your editor of choice. After adding the export command, run either source ~/.bashrc or restart your shell.

Go should be available after this.

This also works if you have a python module installation path that needs to be added to the source.

huangapple
  • 本文由 发表于 2021年9月12日 22:47:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/69152479.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定