In Ubuntu WSL, how can you store permanent environment variables?
Answer a question
I've tried but every time I restart my system my variables are gone.
How can I store my environment variables in a permanent way on Ubuntu WSL2?
Answers
There are a few ways to go about this.
-
First, and the normal method (as you've discovered), is by setting the environment variables in your shell startup scripts. For bash, this would be
~/.bash_profile, for zsh it would be~/.zprofile, and for fish it would be~/.config/fish/config.fish. -
But let me also suggest that you consider trying out the fish shell, as it has a great feature in its ability to set "universal variables", which are automatically propagated to all other instances of the shell, both present and in the future.
E.g.
set -Ux myvariable 42will create a universal (and exported) variable that will persist even after you close and reopen the shell, without having to create config files.Fish has a number of other great features that make it my go-to shell (after 15 years on zsh).
That said, I'm not sure what your goal is with WSL, but if it's to "learn Linux", then you might be better off starting with bash or zsh since they are more "traditional" shells, with bash, of course, being the defacto starndard.
更多推荐
所有评论(0)