5

I am used from Ubuntu to set a path in /etc/environment, i. e. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" is the contents of this file on my Ubuntu system.

I just spent an hour trying to make this work in Raspbian, only to find out that this seems to be ignored completely on Raspbian Jessie. I finally gave up and put the desired path change in /etc/profile.d, where it works as expected.

Can someone enlighten me of why the /etc/environment is ignored on Raspbian?

  • Try putting some other variable there and checking it after login, e.g., FOO=bar, then echo $FOO to see if it is being used. If so, perhaps something else is resetting $PATH subsequently. – goldilocks Oct 30 '15 at 13:36
7

Can someone enlighten me of why the /etc/environment is ignored on Raspbian?

It isn't. Add this to /etc/environment:

FOO=bar

Login, and echo $FOO. It's there.

/etc/environment isn't actually sourced by the shell, it's used by the authentication system (PAM) to set an environment before your login shell is executed. The idea here is to allow for setting env variables in a shell agnostic way -- while bash and other POSIX shells will source stuff like .profile, other shells may not. However, the environment is actually part of, and inherited by, all processes (not just shells), so by setting it before any shell is executed, PAM guarantees those variables will be set.

Of course, they can then be overridden and presumably this is what is happening with $PATH. If you are using bash, it is probably more hassle than it is worth to figure out what by, but very likely it is /etc/profile, since on Raspbian that contains:

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else

 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
fi
export PATH

Rather than edit this, the method you're using -- adding your own file to /etc/profile.d -- is preferable. It guarantees your changes will not be overridden by system updates.

  • The best answer - maybe the only one here, but beats everything else I read on the subject while googling around. Thanks for making this clear! – emk2203 Oct 30 '15 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.