Why doesn't my environment variable get set?
Solution 1
It looks like it's just a bug that my environment variable is not being set.
Solution 2
As you have identified, your environment variables should be set in ~/.pam_environment
as recommended on https://help.ubuntu.com/community/EnvironmentVariables. Easier said than done ;)
It is possible that you ran into the same configuration gap that existed for me. See the workaround for encrypted home below.
My ~/.pam_environment
:
PATH DEFAULT=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${HOME}/bin
IDEA_JDK DEFAULT=${HOME}/Applications/jdk
Why the ugly static path? ${PATH}
would not work for me. I bricked my login several times trying to work around it so I am sticking with the ugly static copy of the defaults :)
Workaround for encrypted home folders
In Ubuntu releases up to and including Ubuntu 12.04 (Precise Pangolin) Beta 2, if you are using an encrypted home directory you will need to modify /etc/pam.d/common-session
to get it to load ~/.pam_environment
. This solution apparently works for earlier releases, but I have not tested it.
Guenther Montag (g-montag) wrote on 2010-08-19:
This seems to be an issue with encrypted home directories. I added
session required pam_env.so
at the end of /etc/pam.d/common-session and now ~/.pam_environment gets read. On another system without encrypted home directories (also 10.04) the work around is not needed. Perhaps in my case the system tries to read ~/.pam_environment before it is decrypted.
Solution 3
Stick to the simple "key=value" syntax in the ~/.pam_environment file. No DEFAULT, OVERRIDE, ${HOME}, no nothing. Just key=value. The man page you linked to is for pam_env.conf, only. See "man 8 pam_env" which does not promise anything else "This module can also parse a file with simple KEY=VAL pairs on separate lines.".
By the way putting something like PATH=${PATH}:more/paths in ./pam_environment is a great way to break almost any attempt to login, since the PATH gets set to ${PATH}:more/paths literally (not much to be found there). To rescue, "/bin/mv .pam_environment out_of_the_way" and re-login.
Solution 4
You have a space in between GDK_NATIVE_WINDOWS and DEFAULT=true . This differs from the example you linked.
Try:
GDK_NATIVE_WINDOWS=true
Related videos on Youtube
reprogrammer
Updated on September 17, 2022Comments
-
reprogrammer over 1 year
I have to set an environment variable called
GDK_NATIVE_WINDOWS
to fix the problem with Eclipse buttons in Ubuntu. To set the environment variable, I added the following line to~/.pam_environment
.GDK_NATIVE_WINDOWS DEFAULT=true
Surprisingly, the environment variable doesn't get set when I
echo $GDK_NATIVE_WINDOWS
in a terminal. However, all other environment variables that I've listed in~/.pam_environment
are set properly. Besides, when I switch to a tty, e.g.Alt+Ctrl+F1
, the environment variable gets set correctly. What's wrong with setting this environment variable in~/.pam_environment
?-
Benjamin Bannier about 14 yearsdid you restart your X session?
-
-
Ignacio Vazquez-Abrams about 14 years
pam_env
doesn't use shell syntax. linux.die.net/man/5/pam_env.conf -
reprogrammer about 14 yearsIt's recommended to use .pam_environment not shell scripts. See help.ubuntu.com/community/EnvironmentVariables
-
reprogrammer about 12 yearsMy home folder is not encrypted.
-
Gili almost 12 yearsIt's not a bug. That's not a valid syntax for ~/.pam_environment. See manpages.ubuntu.com/manpages/hardy/man5/pam_env.conf.5.html
-
reprogrammer almost 12 years@Gili My example matches the syntax
VARIABLE [DEFAULT=[value]] [OVERRIDE=[value]]
at the link you posted. Note that I'm using${}
rather than@{}
to refer toHOME
andPATH
because they are environment variables. -
reprogrammer almost 12 years@kmarsh My example matches the syntax
VARIABLE [DEFAULT=[value]] [OVERRIDE=[value]]
at manpages.ubuntu.com/manpages/hardy/man5/pam_env.conf.5.html. This explains the space beforeDEFAULT
. -
mu1988 over 11 years@reprogrammer That manpage only applies to /etc/security/pam_env.conf. ~/.pam_environment and /etc/environment use a simpler syntax.
-
TwoD over 5 yearsNot likely a bug, something else probably overrides it later, like your X profile as it works with just a shell. The
VARIABLE [DEFAULT=[value]] [OVERRIDE=[value]]
syntax is valid for~/.pam_environment
.${HOME}
and${PATH}
are empty at this point because it runs so early, but you can set them here.@{HOME}
refers to the home as specified in/etc/passwd
. Note that environment variables (and@{HOME}
and@{SHELL}
) are not expanded in thename=value
syntax, you have to usename DEFAULT=value [OVERRIDE=val2]
for that. -
Peter Mortensen almost 4 yearsBut system software (e.g. Ubuntu MATE and Cinnamon, e.g. 20.04 LTS) changes the content of file
~/.pam_environment
with lines such asLC_TIME DEFAULT=en_DK.UTF-8
, suggesting it is valid. Are they in error? -
Marc van Leeuwen almost 4 years@PeterMortensen It is conceivable that my answer from 2013 does not accurately describe the situation in 2020.