Reputation: 1
I know that export USER="name" would make the variable available to all child sessions from the one I'm currently in. But if I restart my computer, will these environment variables return to their default value rather than what I assigned them?
Upvotes: 0
Views: 363
Reputation: 14404
On Linux, environment variables are not persisted, they are kept in each process memory. When a machine is restarted, all those processes will get terminated, and their environment variables will be lost.
The common way to get "persistent" environment variables is to inject their assignment into one of the files that are loaded when the machine reboot, or when a user session is started: /etc/profile (for global settings), or one of the user specific files: ~/.bash_profile, ~/.bash_login or ~/.profile.
An alternative strategy, if the variables are needed just for one session, is to place into a ".sh" file, and "source" the ".sh" file when the variables are needed.
Upvotes: 1
Reputation: 1869
If it's in your .bash_profile, then yes, it should persist across reboots. As long as you're using bash, of course.
Upvotes: 0