14

I am trying to add JAVA_HOME system-wide and also add JAVA_HOME/bin to PATH (Ubuntu 12.04). If I add the following 2 lines at the end of /etc/environment, I cannot login anymore afterwards. If I add the 2 lines to /etc/profile everything works. Wheres the problem?

export JAVA_HOME="/usr/lib/jvm/java-7-oracle"
export PATH="$PATH:$JAVA_HOME/bin"

There is already the following line in /etc/environment (line 1):

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
reikje
  • 2,582
  • 2
  • 22
  • 38

2 Answers2

17

Just write

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

on your /etc/environment, without the "export"

CerealKiller
  • 179
  • 1
  • 2
  • 1
    Why the double quotes? Isn't it enough to write `JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre`? – isapir Dec 03 '19 at 21:04
13

/etc/environment is supposed to contain a set of environment variables given as key=value pairs. It is not a shell script, so you can't use shell commands such as export in it.

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264