0

How can I set an permanent environment variable per user independent from the used shell (bash, zsh and fish)?

BuZZ-dEE
  • 2,103
  • 2
  • 18
  • 24

2 Answers2

1

EDIT: according to What's the best distro/shell-agnostic way to set environment variables?, the best solution for this is ~/.pam_environment

EDIT: reverted to the hacky solution since ~/.profile is not read by all shells:

All shells source /etc/profile.

That means in /etc/profile, you could put a line like

. $HOME/.custom-profile

Then, you could add your variables to ~/.custom-profile for each user

tbrugere
  • 996
0

All shells read different per-user profile files (zsh: ~/.profile, bash: ~/.bash_profile, csh has only an rc file, and so on). So you'd have to change all of these potential candidates.

However, most shells at the very least fall back to reading ~/.profile (thanks @terdon for pointing this out!), so that's where you can put your exports.

Since "logging in" is usually done by a process having the ability to change its uid and gid (typically: a login manager runnning as root), it's up to these programs to define the environment for the spawned program (e.g. a shell).

But: there's more than one login manager (your GDM/lightdm/KDM/... visual login manager, getty, logind/loginct, ssh, getty...), and they read configuration from different files, so there's no consistent way there, either.