How can I found where I defined JAVA_HOME
Asked Answered
H

5

6

Here is my system info

wangbo@ubuntu:~$ uname -a
Linux ubuntu 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

When I check java version

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

but when I echo $JAVA_HOME

/usr/lib/jvm/java-9-oracle

It is unmatched , It seems that I defined $JAVA_HOME somewhere , but I can`t found it , Anyone can help me how can I found my $JAVA_HOME defined

Other useful info :

  1. I had install and uninstall jdk9 as first jdk before
  2. It is not in ~/.bashrc
  3. It is not in /etc/bash.bashrc
  4. It is not in ~/.profile

UPDATE

wangbo@ubuntu:~$ more /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
Hibbs answered 5/4, 2017 at 11:10 Comment(2)
Try grepping in ~ and /etc/, e.g. grep java-9-oracle /etc -R.Demiurge
use update-alternative or similar to reset to the default (here I have a /etc/profile.d/jdk.sh)Nocuous
P
18

1) JAVA_HOME is most probably defined in /etc/profile.d/jdk.sh and /etc/profile.d/jdk.csh These files are unfortunately not managed by the update-alternatives system.

2) Which executable you run should depend on the update-alternatives system, but if you have forced a particular version in your PATH it won’t.

Many java applications are actually invoked by scripts which choose their preferred jvm setting up a consistent environment, and shouldn’t be affected by your problem. It is best to have a consistent environment for free java invocations from the shell, however, and in most installations I know this is achieved manually...

Some java distributions don’t need JAVA_HOME at all. In other cases you need it. My advice is to define JAVA_HOME only when it turns out you need it. If it is the case, define it in a shell script and use that script to invoke the commands that you need that particular value for.

EDIT: /etc/profile.d/jdk.sh seems to be installed by oracle-java8-set-default.

# Uninstall the package (choose one)
sudo apt purge oracle-java8-set-default
sudo apt remove --purge oracle-java8-set-default

# Configure the desired Java binary
sudo update-alternatives --config java
sudo update-alternatives --config javac
Pirtle answered 5/4, 2017 at 11:38 Comment(2)
I delete /etc/profile.d/jdk.sh and reboot , JAVA_HOME is no longer exsit It seems that I have to config JAVA_HOME by myself and when I change Java version with update-alternatives I need to modify it again , is there any resolvent ?Hibbs
@Hibbs JAVA_HOME is not really needed in many cases. (It is if you use Oracle jvm.) I added paragraph to my answer with some advice.Pirtle
L
0

you should better check /etc/environment

Laure answered 5/4, 2017 at 11:16 Comment(1)
Update It seems that I haven`t defined JAVA_HOME in /etc/environmentHibbs
T
0

On my ubuntu 14.04 system, kernel 4.4.0-71-generic I used the following:

$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
Tecla answered 5/4, 2017 at 11:21 Comment(0)
F
0

Your Java command is picked up from the PATH variable. Most probably, you have added Java7 to your path. Check your .profile, .bash_profile, /etc/profile and /etc/environment files.

JAVA_HOME is used by some scripts/tools (ant comes to mind) - to select a java command.

Feathery answered 5/4, 2017 at 11:26 Comment(0)
E
0

Try

sudo find / -path /sys -prune -o -path /proc -prune -o -type f -exec grep -l JAVA_HOME {} + 2>/dev/null

Sorry the first version of my answer will take forever. But this will take only some time, but it will find the file.

Exaggerative answered 5/4, 2017 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.