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?
So this is the way that worked for me:
~/.bash_profile is the correct file for permanent environment variables if using Bash on Ubuntu WSL2, however make sure you add the export keyword before your variables, like so:
export THISVAR=thisIsAVar
export ANOTHERVAR=anotherVar
To add the variable(s) use the command sudo nano ~/.bash_profile (if you prefer Nano editor) or sudo vim ~/.bash_profile (if you prefer Vim). After you have entered your variables into the .bash_profile save the file and then enter source ~/.bash_profile to have the variables available in the terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With