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

Viewed 4132

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 Answers

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.

Related