Interview Prep/Linux/Packages, Shell & Text Tools

Where should you set environment variables persistently?

IntermediateConceptPackages, Shell & Text Tools
Answer
  • Per user, interactive: ~/.bashrc or ~/.profile.
  • System-wide for login shells: a script in /etc/profile.d/*.sh.
  • System-wide simple KEY=value: /etc/environment (read by pam_env, no shell expansion).
  • For a service: Environment= or EnvironmentFile= in the systemd unit. Services do not read .bashrc or /etc/profile.
All Linux questions Roadmap: Linux

More on Packages, Shell & Text Tools