Why do I get duplicated entries in my $PATH?

I'm using Ubuntu 9.10 (karmic). And, my ~/.pam_environment looks like the following.

PATH            DEFAULT=${PATH}:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux
GIT_EDITOR      DEFAULT=vim
MANPATH         DEFAULT=${MANPATH}:~/texlive/2009/texmf/doc/man
INFOPATH        DEFAULT=${INFOPATH}:~/texlive/2009/texmf/doc/info

But, echo $PATH returns me duplicated entries as the following.

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux:~/Adobe/Reader9/bin:~/texlive/2009/bin/x86_64-linux

I've tried replacing DEFAULT by OVERRIDE in my ~/.pam_environment file. But, that didn't help.

Does any one know what's wrong with my ~/.pam_environment?


The problem seems to stem from the fact that pam_env defaults to reading the user ~/.pam_environment every time it is invoked. A lot of login methods (cron, lightdm, lightdm-autologin, login, sshd and su on my machine) invoke pam_env twice: once to read the /etc/environment and ~/.pam_environment files, and once to read the /etc/default/locale file. In neither case is the user_readenv flag set, so pam_env reads, and acts on, your ~/.pam_environment twice.

To fix this, go to your /etc/pam.d directory, and add the following to every line in which pam_env is invoked with the envfile=/etc/default/locale option:

user_readenv=0

Check your /etc/pam.d/ that pam_env.so isn't loaded twice somehow, such as both in session and in auth.