1

I installed java in opt/jdk1.7.75 having following directories-->

bin
db
include
jre
lib
man
COPYRIGHT
LICENSE
README.html
relase

& other files I set JAVA_HOME path in .bashrc file as follow:

JAVA_HOME=/opt/jdk1.7.75
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH

On running echo $JAVA_HOME path it is pointing as follow:

/opt/jdk1.7.75

My question is How to verify if the path is correct or incorrect? As most post says run echo command, echo simply gives the path what u have set,it does not tell you if it is correct or incorrect.

Can anybody explain How to VERIFY path is correct or incorrect

Thanks in advance

2
  • Please take a look at editing-help.
    – Cyrus
    May 2, 2015 at 7:10
  • You want JAVA_HOME to override other things in PATH, so it should come first: export PATH="$JAVA_HOME:$PATH"
    – muru
    May 2, 2015 at 7:39

3 Answers 3

2

Your $JAVAHOME is pointing to the correct location. But the path should have $JAVAHOME/bin directory and not $JAVAHOME itself.

JAVA_HOME="/opt/jdk1.7.75"
export JAVA_HOME
PATH="$PATH:$JAVA_HOME/bin"

You should consider using the Oracle Java PPA instead. It usually does more than what a manual installation would do. You don't have to worry about setting up the environment variables either. That's what most people use.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

Try running java -version and javac -version to verify that the path is set.

14
  • thanks for ur ans, but my question was how to verify? is there any command or someway, which tells JAVA_HOME path is incorrect? May 2, 2015 at 7:23
  • Just try running java -version and javac. May 2, 2015 at 7:28
  • java -version gaves the same output as it was giving before setting JAVA_HOME path, same goes for javac May 2, 2015 at 7:31
  • @NarendraJaggi See the updated answer. May 2, 2015 at 7:41
  • Put $JAVA_HOME/bin before the existing entries in PATH: export PATH="$JAVA_HOME/bin:$PATH". Otherwise /usr/bin/java will override $HAVA_HOME/bin/java.
    – muru
    May 2, 2015 at 7:46
0

If you have update-java-alternatives installed, just type

$>update-java-alternatives -l

From the manual man update-java-alternatives

DESCRIPTION update-java-alternatives updates all alternatives belonging to one runtime or development kit for the Java language. A package does provide these information of it's alter‐ natives in /usr/lib/jvm/..jinfo.

OPTIONS -l|--list [] List all installed packages (or just ) providing information to set a bunch of java alternatives. Verbose output shows each alternative provided by the pack‐ ages.

If you don't have it installed, simply run

$>ls -l /usr/bin/java

It should return a pointer to the java bin file, something like

$>ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 ott 16  2013 /usr/bin/java -> /usr/lib/jvm/java-8-oracle/jre/bin/java

JAVA_HOME is the part previous to jre, so in my case /usr/lib/jvm/java-8-oracle

0

if you are able to run java commands like

java --version

from the terminal, the PATH is correct and in turn, the JAVA_HOME variable is correct.

4
  • without PATH these command will not run? May 2, 2015 at 20:20
  • yes, they wont. If you want to run an executable file saved in /path/to/executable/, you have to give /path/to/executable/file to run it if it is not saved in PATH or any other environment variable. The very fact that you are able to run java --version proves that your path is right.
    – tbking
    May 2, 2015 at 20:33
  • i didn't set, but its wrkng, may b i use java alternative command so these things r nt reqrd, as i didn't set any path @ first point May 2, 2015 at 20:42
  • run env | grep java . If there is a path to your java location. It is set.
    – tbking
    May 2, 2015 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .