1

I remember in the past, we have two place to set env variables for Ubuntu

  1. Login shell - ~/.profile
  2. Non login shell - ~/.bashrc

But now according to the doc [1], they are not recommended anymore. And we should use ~/.pam_environment, but my understanding is this is for login shell, so how about non login shell?

Where should I use?

[1] https://help.ubuntu.com/community/EnvironmentVariables

1 Answer 1

2

~/.pam_environment (and /etc/environment) is parsed when you log in (including when you log in graphically). After that, all processes run from a logged in session will inherit the environment variables set in those two files.

Note though, that ~/.pam_enviornment is not a shell script. It only accepts KEY=VALUE pairs; it won't expand ~ or $VAR or any other such shell syntax, so it's not usable for all cases. If you want to prefix/append ~/bin to PATH for instance, you'll have to do that in ~/.profile. Because PATH=~/bin:$PATH won't be interpreted correctly by pam_env.

~/.profile is also read when you log in graphically.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .