6

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?

asked Oct 30, 2015 at 12:42
1
  • 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. Commented Oct 30, 2015 at 13:36

2 Answers 2

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.

answered Oct 30, 2015 at 14:12
1
  • 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! Commented Oct 30, 2015 at 17:24
0

It's an old question but I would like to add some possibilities.

Some people will use Dropbear SSH rather than OpenSSH server on Raspberry Pi for lower memory consumption, but unfortunely Dropbear SSH does not support full PAM configuration for now, therefore /etc/environment is not included during login.

In this case Dropbear SSH will use DEFAULT_PATH defined in src/default_options.h, which is "/usr/bin:/bin" for now:

/* The default path. This will often get replaced by the shell */
#define DEFAULT_PATH "/usr/bin:/bin"
#define DEFAULT_ROOT_PATH "/usr/sbin:/usr/bin:/sbin:/bin"

Also other variables inside /etc/environment will not work.

answered Oct 24, 2024 at 17:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.