/etc/environment is officially the correct place for system wide environment variables. But how can I reload the assignments in this file without rebooting or relogging?

Interestingly enough google does not help me here, aside from the dozens of blog posts suggesting to use

source /etc/environment

which obviously will never work because /etc/environment is a list of assigments (one per line) and not an executable script (hence the missing export commands in /etc/environment ...).

link|improve this question
2  
Systemwide, I have no idea. For the current shell session, you can use for line in $( cat /etc/environment ) ; do export $line ; done, if the file format is key=value. – Daniel Beck Sep 25 '11 at 11:38
feedback

1 Answer

up vote 4 down vote accepted

One thing you are mistaken about is that /etc/environment requires a reboot to reload. This is incorrect. The only time the file is read is on login, when the PAM stack is activated – specifically pam_env.so, which reads the file.

Logging out and back in would apply the changes – and in fact you must do this if you want all your processes to receive the new environment. All other "solutions"2 will only apply the environment to the single shell process, but not to anything you launch through the GUI including new terminal windows.1

If you're fine with that, though – the lack of export commands can be compensated for with set -a and set +a. However, it still remains a poor way, as the file doesn't use quoting either. But this should work fine:

while read -r env; do export "$env"; done

1 GNOME Session Manager provides a way to change its own environment, but only during the Initialization phase:

$ gdbus call -e -d org.gnome.SessionManager -o /org/gnome/SessionManager \
    -m org.gnome.SessionManager.Setenv "foo" "bar"
Error: GDBus.Error:org.gnome.SessionManager.NotInInitialization: Setenv
    interface is only available during the Initialization phase

2 gdb is not a solution (unless you are grawity).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.