0

On RHEL 6.7, I've added the file /etc/environment:

JAVA_HOME="/opt/jdk1.8.0_91"
JRE_HOME="{JAVA_HOME}/jre"
M2_HOME="/usr/local/apache-maven"
M2="{M2_HOME}/bin"
PATH="{JAVA_HOME}/bin:{JRE_HOME}/bin:{M2}:{PATH}"

Now on login, bash gives the following errors:

-bash: id: command not found
-bash: id: command not found
-bash: id: command not found
-bash: uname: command not found

Removing or renaming /etc/environment makes the problem go away.

Note: I do not want to use /etc/profile because I want these settings to be available to non-interactive shells.

Paul Croarkin
  • 173
  • 1
  • 1
  • 6

1 Answers1

3

/etc/environment doesn't perform variable expansion. Thus, your PATH is now literally {JAVA_HOME}/bin:{JRE_HOME}/bin:{M2}:{PATH}, which won't work of course.

If you use bash only, you might want to look into setting $BASH_ENV in /etc/environment like so:

BASH_ENV=/etc/non-inter-test

where /etc/non-inter-test is then read and executed by non-interactive shells (and only those, so you must reference the same file in /etc/profile for interactive shells) and might contain what is now in your /etc/environment.

Sven
  • 97,248
  • 13
  • 177
  • 225