Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ubuntu WSL, how can you store permanent environment variables? [closed]

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?

like image 403
Nomnom Avatar asked Nov 20 '25 18:11

Nomnom


1 Answers

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.

like image 95
Nomnom Avatar answered Nov 22 '25 10:11

Nomnom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!