1

I have CentOS 6.7. I installed OpenJDK 1.8 with the following command.

yum install java-1.8.0-openjdk-devel

After installing I executed the following two commands.

export JAVA_HOME=/usr/jdk/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH

But when I type java -version I still see the following output. I do not see OpenJDK.

java version "1.8.0_121"

Java(TM) SE Runtime Environment (build 1.8.0_121-b13)

Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

EDIT

I have posted a similar thread, regarding not finding 'javac' in the thread -bash: javac: command not found” error after installing OpenJDK 1.7 In that thread I was not able to execute javac which was resolved and it was about OpenJDK 1.7 (not 1.8). But this thread is all about java -version not showing OpenJDK for OpenJDK 1.8.

KurioZ7
  • 503
  • 6
  • 10
  • 19
  • 1
    You appeared to have installed the "devel" package, which looks to me like it installs `.../bin/java` to a subdirectory of `/usr/lib/jvm/`, not `/usr/jdk/` – Jeff Schaller Apr 06 '17 at 12:33
  • Possible duplicate of ["-bash: javac: command not found" error after installing OpenJDK 1.7](http://unix.stackexchange.com/questions/355817/bash-javac-command-not-found-error-after-installing-openjdk-1-7) – Jeff Schaller Apr 06 '17 at 12:38
  • Possible duplicate of [Bash remembers wrong path to an executable that was moved/deleted](http://unix.stackexchange.com/questions/335801/bash-remembers-wrong-path-to-an-executable-that-was-moved-deleted) – G-Man Says 'Reinstate Monica' Apr 07 '17 at 03:56
  • One strange thing I have observed it that, after I removed OpenSDK 1.8 by executing yum remove command, I still see the same output for java -version command. If I execute the command yum list installed | grep java* I do not see OpenSDK 1.8 package. So I am now really confused. – KurioZ7 Apr 07 '17 at 04:07
  • Use `type java` in bash to find out what you're actually running, and if it's a link follow to its (final) target, then do `rpm -qf` on that file. Also: Java is OpenJDK, not OpenSDK, which is several somethings completely different. @JeffSchaller: similarly java-1.8.0-openjdk-headless, which is JRE-minus-AWT, installs to /usr/lib/jvm/fullversion/jre, not /usr/jdk. And the CentOS 6 repositories I use (AFAIR default) don't (now?) have any java-ver-oracle/sun versions at all. – dave_thompson_085 Apr 07 '17 at 06:56

1 Answers1

1

Below are steps to find the java:

find / -name java | grep "/bin/java" ---> This will give all paths where you have executable of java

[root@XXXXX ~]# find / -name java | grep "/bin/java"
/usr/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.el6_10.x86_64/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.el6_10.x86_64/jre/bin/java

Once you find the locations just make the below entry for java home for machine: vi /etc/profile ---> add the below lines to the end

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-1.el6_10.x86_64
export PATH=$JAVA_HOME/bin:$PATH

[root@XXXXX ~]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

In your example you are giving path for JDK not for OpenJDk as below: export JAVA_HOME=/usr/jdk/jdk1.8.0_121 export PATH=$JAVA_HOME/bin:$PATH

Thats why it is showing java even though you have installed OpenJDK.

Let me know if you have any queries.

Santosh Garole
  • 358
  • 1
  • 4
  • 16
  • If this works for you @KurioZ7 Can you please accept the answer. For accepting it please follow: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Santosh Garole Apr 17 '20 at 14:39