@luke_gadget
Linux Oct 19, 2026

Adding an environment variable permanently on ubuntu

I set a variable with export and it works, but it's gone as soon as I close the terminal. Where should it go so it sticks for my user? bashrc, profile, or /etc/environment?
1

Leave A Reply

Log in to post an answer.

1 Answer

leah_fixes Oct 21, 2026
luke_gadget
Just for you: add a line like export MY_VAR="value" to the end of ~/.bashrc, then run source ~/.bashrc or open a new terminal. For every user and not only bash, put MY_VAR="value" in /etc/environment (no export there, it isn't a script) and log out and back in. The classic gotcha is setting it in .bashrc and then wondering why a desktop app or cron job can't see it. Those don't read .bashrc, so use /etc/environment or ~/.profile for those.