I have seen other people on the Internet also having this problem but the solutions have been non-conclusive, so I wanted to bring it to attention again.
According to this page in Ubuntu wiki: https://help.ubuntu.com/community/EnvironmentVariables the recommended way to set session-wide environment variables is to modify ~/.pam_environment.
Here is what my goal is:
- I want to create an environment variable ANDROID_HOME that would have a path to a certain location in my home folder as a value.
- I want to add two folders to the PATH.
Here is what I did. The ~/.pam_environment file was non-existent, so I created it and added the following lines to it:
ANDROID_HOME=${HOME}/Android/Sdk
PATH DEFAULT=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
Logged out and logged back in.
The result is not expected. I opened terminal and echoed $ANDROID_HOME and that's what I got:
${HOME}/Android/Sdk
Looks like the ${HOME}
is not replaced with my home folder path. Why is that so?
Observe cd
-ing to $ANDROID_HOME (the Android/Sdk actually exists in my home folder):
anvar@crazymachine:~$ cd $ANDROID_HOME
bash: cd: ${HOME}/Android/Sdk: No such file or directory
Also echoing $PATH gave me this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:${HOME}/Android/Sdk/tools:${HOME}/Android/Sdk/platform-tools
Why are the variables not substituted with their values like would be logical to assume, especially when the example in the aformentioned site gave such an impression that variables can be used inside the values?
What is the right way to set session-wide environment variables that also GUI programs have access to?
~/.pam_environment
is described at pam_env.conf(5).