How to reload /etc/environment without rebooting?
Solution 1
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, but can be used sometimes. You have to attach it to the running processes of your session manager (e.g. gnome-session
), your window manager (e.g. gnome-shell
or openbox
), your taskbar/panel if any (e.g. xfce4-panel
), and generally anything else that possibly would run stuff. For each of those processes, you need to attach gdb
to it by PID, invoke the putenv()
function using p
, then detach using q
:
$ sudo gdb -p $(pidof gnome-session)
GNU gdb (GDB) 7.7.1
[...]
Attaching to process 718
[...]
0x00007fc2cefed81d in poll () from /usr/lib/libc.so.6
(gdb) p putenv("FOO=bar")
$1 = 0
(gdb) p putenv("BAZ=qux")
$2 = 0
(gdb) q
A debugging session is active.
Quit anyway? (y or n) y
Detaching from program: /usr/bin/gnome-session, process 718
Note that the debugger pauses the process, therefore you must attach to compositing window managers only from another tty (virtual console) or over SSH, otherwise the screen would freeze.
In addition to that, you should also update the environment used by dbus-daemon:
$ dbus-update-activation-environment --systemd FOO=bar BAZ=qux
For older systems:
$ gdbus call -e -d org.freedesktop.DBus \
-o /org/freedesktop/DBus \
-m org.freedesktop.DBus.UpdateActivationEnvironment \
"{'FOO': 'bar', 'BAZ': 'qux'}"
()
Solution 2
This is not as comprehensive as the accepted answer, but if you have quoted variables in your /etc/environment
files both previous methods (which use export $line
somehow) will go wrong and you end up with quoted values.
- Option 1: with a temporary source-able file
sed 's/^/export /' /etc/environment > /tmp/env.sh && source /tmp/env.sh
- Option 2: with inline
for
(thanks @tim-jones):
for env in $( cat /etc/environment ); do export $(echo $env | sed -e 's/"//g'); done
- Option 3: with the
allexport
bash option (thanks @ulidtko):
set -a; source /etc/environment; set +a;
Related videos on Youtube

Imran H
Updated on September 18, 2022Comments
-
Imran H 8 months
I have a jasper report which has 12 columns. 10 of these columns were defined with width 160 and other 2 with width 480. While the report could be opened in PDF and excel successfully, it could not export in docx. I decreased the width. Made each field as 100 and bigger 2 as 200. But very shockingly this has resulted in lesser number of rows being resulted. This is completely baffling to me. Any help on this would be appreciated.
Thanks
-
HikeMike over 11 yearsSystemwide, 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 iskey=value
. -
badboy24 about 9 yearsWorks for me without an
export
... -
Gert van den Berg over 8 years@lzkata: If a variable is already exported, it should not be necessary to export it again... If new variable that have not already been exported are added, the
export
would be necessary... (without it it is just a normal non-environment variable in the current shell, not available in child processes) -
Petter Friberg over 7 yearsIts probably wrapping the text (hence shorter columns, text goes to new line, record take more space...) being resulted?.. what means? I interpreted as less rows on page... do you mean rows missing??
-
Imran H over 7 yearsMissing rows is what I meant. Sorry for not explaining earlier. Number of rows in excel decreased from 1100+ to somewhere around 900.
-
Petter Friberg over 7 yearsThis seems very strange... can you post some relevant jrxml code, surely some other issue than column size.. isPrintRepeatedValues="false"
-
Imran H over 7 yearsI figured out what was wrong. I found out there were lesser number of rows in excel but in PDF I could see blank rows. Culprit was 'Position Type' set to 'Fix Relative to Bottom' and 'Stretch Type' set to 'Relative to Tallest Object'. Changing these two settings fixed the issue. It was missing rows in excel which completely took me by surprise. Thanks for your inputs.
-
Petter Friberg over 7 yearsGreat : ) ...consider posting answer (accept it) or delete question... so that this can be closed.
-
Gadelkareem over 7 years@DanielBeck thank you..plz add you comment as an answer!
-
Massimo almost 6 yearsdoes it works also on debian and centos ?
-
Massimo almost 6 yearsdoes it require user login or its settings are used also by daemons and cron jobs ?
-
Nicholas Saunders over 2 yearsI'm just curious why all the blog posts I see also suggest to use
source /etc/environment
when it doesn't work (for me)
-
-
Frank almost 7 yearsI just tested while read -r env; do export "$env"; done on Ubuntu 16.04 and it errors. Would you like more details?
-
villasv almost 6 yearsThe
while read
method reads fromstdin
, so you probably want to pipe something to it (e.g.cat /etc/environment | while ...
). But this won't work with quote formatted environment files (key="value"
) -
Aaron McMillin almost 6 yearsShorter: eval
sed 's/^/export /' /etc/environment
-
Tim Jones about 5 yearsNon-temp-file version of above:
for env in $( cat /etc/environment ); do export $(echo $env | sed -e 's/"//g'); done
-
Massey101 about 5 yearsEven shorter:
set -a; source /etc/environment; set +a;
. -
Tobia about 3 yearsThank you! I've been looking for (and trying to come up with) an elegant solution like your
read -r
for a while, to parse generic "env files" like those used with Docker etc. Here is a more complete example, which skips blank lines and lines starting with#
(as is common in env files nowadays) and exits with an error if a line is malformed:while read -r pair; do if [[ $pair == ?* && $pair != \#* ]]; then export "$pair" || exit 2; fi; done < SOME_ENV_FILE