I'm using RHEL8 which has default OpenJDK installed. which java command points to /usr/bin/java. java -version gives openjdk version "1.8.0_252"
Installed java in /u01/app/java/ location. Modified the.bashrc like below & sourced it. export JAVA_HOME=/u01/app/java/jdk1.8.0_241/ PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH" export PATH
Now JAVA_HOME points to /u01/app/java/jdk1.8.0_241/ But which java or java -version still points to the OpenJDK.
How can i fix it?
It was Path issue. I have given PATH="$JAVA_HOME/bin/java:$HOME/.local/bin:$HOME/bin:$PATH" for PATH. which should not be the case. Modified my PATH to below. It worked.
PATH="$JAVA_HOME/bin:$HOME/.local/bin:$HOME/bin:$PATH" export PATH
That happens because when you invoke java it is actually invoked /usr/bin/java
, which, issuing ls -l /usr/bin/java
you will probably see is linked to the openjdk installation (probably through a double link: the first one being /usr/bin/java
to /etc/alternatives/java
and the second one being the link to the "real" java executable). For example, on my debian:
gianluca@asus-debian:~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 mag 20 2018 /usr/bin/java -> /etc/alternatives/java
gianluca@asus-debian:~$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 43 nov 22 2019 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
You can fix in two ways:
You can read more about alternatives for RHEL here (mid-page... "The longer version").
Good link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.