Setting a variable without logging out
A modern GNOME session runs under systemd; GUI applications inherit that environment:
| |
The first sets it for systemd user services and later shell-launched applications; the second makes D-Bus-activated apps see it, how most GNOME apps start.
echo $MY_VAR prints nothing: variables are copied into a process at start, and your shell predates the change. Shell and systemd user session do not propagate:
| |
The first confirms the setting, the second imports it into the current shell.
Persistent, in a drop-in read at session start:
| |
Where not to put it: ~/.profile and ~/.bashrc need a new login, /etc/environment a logout or reboot, and /etc/profile reaches shells only, never the GNOME session.
Running something at login
Autostart, for a GUI program or one needing the session environment — DISPLAY, DBUS_SESSION_BUS_ADDRESS:
| |
| |
| |
A systemd user service, for background, restartable work — more reliable than autostart for anything long-lived:
| |
| |
A shell RC file, for a text login before GNOME: ~/.bash_profile or ~/.bash_login. Anything needing the GNOME session will not work.
Anything requiring sudo will not run at login without passwordless sudo — rewrite it as a system service.