2

I have a Red Hat Linux machine where I am trying to use Java 8.

So I did this:

export JAVA_HOME=/my/path/to/oracle/jdk/1.8/exec export PATH=$PATH:$JAVA_HOME 

However, if I run java -version I get java version "1.7.0_121".

I looked at this similar question, but I don't seem to have the same problem.

If I run $JAVA_HOME/bin/java -version I get java version "1.8.0_72-b15", so JAVA_HOME does point to Java 8.

which java outputs /usr/bin/java.

So how can JAVA_HOME point to Java 8, while java -version points to Java 7?

4
  • 2
    Try: export PATH=$JAVA_HOME:$PATH Commented Mar 9, 2017 at 11:56
  • 1
    what does ls -l /usr/bin/java show? Commented Mar 9, 2017 at 11:58
  • I tried export PATH=$JAVA_HOME:$PATH, but nothing changes. Commented Mar 9, 2017 at 12:52
  • ls -l /usr/bin/java shows /usr/java/default/bin/java. Commented Mar 9, 2017 at 12:55

4 Answers 4

4

I think you did not configured your PATH correctly, try export PATH=$JAVA_HOME/bin:$PATH:

  • Add $JAVA_HOME/bin to $PATH, not $JAVA_HOME, because the full path to java is $JAVA_HOME/bin/java in the description of question.
  • Put your $JAVA_HOME/bin in the head of $PATH, not the tail, otherwise the old java in original $PATH will always be found by shell first.
Sign up to request clarification or add additional context in comments.

3 Comments

You might want to add why this will help.
I've added more descriptions :-)
Default java binary must be managed in Linux using alternatives.
0

I don't know if it helps, but I had a similar problem on Windows.

After some research I discovered that a copy of older version of java.exe was also put into Windows' system32 folder.

Maybe something similar is happening in your case ... however I cannot tell you which folder to look for on linux... may be something like /sbin,/bin,/usr/bin/ etc.

The older version of the file java.exe should be in some directory that is on your path variable. So, you can try echo $PATH to get ideas as where to look.

Also reversing the order export PATH=$JAVA_HOME/bin:$PATH (as suggested by others) also could work, as the first version encountered on the path would be the new version (1.8).

Comments

0

The file /usr/bin/java is a symlink. Just change it to link your Java 8 location as follows:

sudo rm /usr/bin/java sudo ln -s /path/to/java8/jre/bin/java /usr/bin/java 

Notice: you might want to change, as well, every other Java symlinks to have a consistent version of all your Java tools (e.g. javac, javap, etc)

2 Comments

default java version must be managed using alternatives, not manually.
Default Java version can be managed manually or using alternatives, the way that fits you best.
0

Default java binary is managed in Linux using alternatives

someuser@linux:~/tmp> /usr/sbin/alternatives --display java | grep 'priority' /usr/lib64/jvm/jre-1.7.0-openjdk/bin/java - priority 1705 /usr/lib64/jvm/jre-1.8.0-openjdk/bin/java - priority 1805 

Java 8 gets the higher priority. Also, Linux does not use $JAVA_HOME to determine the path to a binary so setting it has no effect in this case.

To set default java version using alternatives refer to this answer: https://askubuntu.com/questions/121654/how-to-set-default-java-version

1 Comment

This does not answer OP's question which is how to change from a version of Java to other.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.