Updated since demoting vote so please if this corrects the issue as it looks like when I used a Virtual machine and arch please vote so I get the -1 removed please.
If your system uses SUDO see 2nd half below...
For Systems that use SU ONLY:
In some systems it can be aliased so even if you use su it auto uses su - which forces the use of the new user's variables as found in their bashrc
Look at your personal user bash.rc for the mentioned alias below and remove it. That should stop it from trying to use the root user's set variables.
page: https://wiki.archlinux.org/index.php/su
Relevant Bit:
Thus, administrators should generally use su as follows:
$ su -
An identical result is produced by adding the username root:
$ su - root
Likewise, the same can be done for any other user (e.g. for a user
named archie):
# su - archie
You may wish to add an alias to ~/.bashrc for this:
alias su="su -"
For SUDO Systems
That's because of the sudo config. I used the following question/answer to get me going: https://askubuntu.com/questions/128413/setting-the-path-so-it-applies-to-all-users-including-root-sudo
Basically:
The manual page for sudoers
states:
env_reset If set, sudo will reset the environment to only contain
the LOGNAME, MAIL, SHELL, USER, USERNAME and the SUDO_*
variables. Any variables in the caller's environment
that match the env_keep and env_check lists are then
added. The default contents of the env_keep and
env_check lists are displayed when sudo is run by root
with the -V option. If the secure_path option is set,
its value will be used for the PATH environment
variable. This flag is on by default.
and this is how to address it:
So, you can do the following to maintain variables when using sudo
sudo visudo
this will open sudo settings for you. Then per what I did you add the following below
Defaults secure_path="blah"
Defaults env_keep +="VARIABLE VARIABLE VARIABLE"
(EXCLUDING PATH as it is set by secure_path) and those are just single spaces between each variable if you wish to have more than 1 maintained.
and what this does is tell sudo which env variables to keep and not disregard.
When done hold ctrl and hit o for Write Out hit enter and say yes to save [even though it specifies a tmp file this is OK it will be written back to the main config just say yes when asked if you wish to overwrite].
That should allow you to maintain whichever variables you wish (a big one being JAVA_HOME and also http_proxy if you use a proxy).
So it should look something like below including your specified variable:
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin/bin"
Defaults env_keep +="GRAILS_HOME"
and to verify it takes exit any open terminal windows and re-open one and run
echo $GRAILS_HOME
It should be what you set, now issue
sudo echo $GRAILS_HOME
and it should now remain unchanged.
The Grails_home reference is from me helping another user on ubuntu communities so just sub that with the name of your variable.
I suspect you missed something in the configuration/compilation phase. You should have been able to find the options that your vendor used to compile the original binary so you could provide those same options. – Zoredache – 2014-11-07T20:08:08.683