Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly set JAVA_HOME in /etc/environment

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"
like image 802
reikje Avatar asked Jan 06 '13 16:01

reikje


People also ask

What should my JAVA_HOME be set to?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.

Should JAVA_HOME point to JDK or JRE?

If you're doing any sort of development, or building with Maven or Ant, you need to point to the JDK (Java Development Kit) where utilities such as javac (the Java Compiler) reside. Otherwise, you can point to the JRE (Java Runtime Environment). The JDK contains everything the JRE has and more.


2 Answers

Just write

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

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

like image 107
CerealKiller Avatar answered Oct 21 '22 09:10

CerealKiller


/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.

like image 39
Quentin Avatar answered Oct 21 '22 08:10

Quentin