Question

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.

Was it helpful?

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

OTHER TIPS

You can install a progam called "galternatives" that will give you a visual representation of your alternatives symlinks to your java binaries.

Of course, you could probably set the JAVA_HOME separately (as an override) in a shell script like so:

JAVA_HOME=/any/location/i/want
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH

Try in your shell:

export JAVA_HOME=/etc/environment

if working, edit your .bash_profile file and add this line again for every session

I had the same problem, this is my solution:

$] uname -a

Linux ******* x86_64 x86_64 x86_64 GNU/Linux

=> downloading a bin :jdk-6u45-linux-x64.bin => In my installation location

$]chmod u+x jdk-6u45-linux-x64.bin
$]./jdk-6u45-linux-x64.bin
...
Done

$]cd jdk1.6.0_45/jre/bin
$]./java -version

java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

It works..

1/ check your server configuration 2/ verify the owner of diretories after unpackaging. 2/ use binary pacquage .bin

Regards.

Richy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top