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?
2 Answers 2
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– emk22032015年10月30日 17:24:13 +00:00Commented Oct 30, 2015 at 17:24
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.
FOO=bar
, thenecho $FOO
to see if it is being used. If so, perhaps something else is resetting$PATH
subsequently.