Search code examples
javaubuntuubuntu-12.04ubuntu-server

Java home in etc/enviroment in Ubuntu


Cannot set JAVA_HOME in /etc/enviroment with JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10/"

The command echo $JAVA_HOME gives me /home/syncsys/bin/jdk1.7.0_10/ but it's not a correct Java HOME or I need something else?

I dont want bashrc or profile (some issues). Only /etc/enviroment and a way to eliminate the need of reboot after /etc/enviroment updates.

My /etc/envirment :

JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10"
PATH=$JAVA_HOME:$PATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

some commands to test :

syncsys@sync-pc:~$ JAVA_HOME=/home/syncsys/bin/jdk1.7.0_10
syncsys@sync-pc:~$ export JAVA_HOME
syncsys@sync-pc:~$ PATH=$JAVA_HOME:$PATH
syncsys@sync-pc:~$ export PATH
syncsys@sync-pc:~$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.6-jre-headless
 * gcj-4.7-jre-headless
 * openjdk-7-jre-headless
 * openjdk-6-jre-headless

update :

$ cat /etc/environment 
JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10"
PATH="$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
syncsys@sync-pc:~$ java -version
The program 'java' can be found in the following packages:

--------(solved) -------- Working sample that is now ok for me.

 $ cat /etc/environment JAVA_HOME="/home/syncsys/bin/jdk1.7.0_10" PATH="/home/syncsys/bin/jdk1.7.0_10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin‌​:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" 

I have read a lot of tutorials and similar forum posts for this but it's not working.


Solution

  • aha! I see the problem...

    your JAVA_HOME is correct (if the path is pointing to your JDK, I hope so). The problem is you should change

    PATH=$JAVA_HOME:$PATH
    

    into

    PATH=$JAVA_HOME/bin:$PATH
    

    because the executable file "java" is not in your JAVA_HOME, it sits in JAVA_HOME/bin