0

I have installed java jdk 9 and java jre 9 on ubuntu and set the path of both to /etc/environment as /usr/local/jdk-9.0.4:/usr/local/jre-9.0.4/bin then I tested javac -version which prints jdk9 but when I run java -version it prints

openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

I don't know where the openjdk is installed. I think it is installed with the MAVEN.

Here is the /etc/environment content

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/jdk-9.0.4/bin"
JAVA_HOME="/usr/local/jdk-9.0.4:/usr/local/jre-9.0.4/bin"
2
  • How did you install jdk/jre9? Via apt? What is the output of update-java-alternatives --list (may need sudo, but not sure)?
    – danzel
    Mar 21, 2018 at 11:05
  • openJDK install automatically when I installed maven. but the other version java 9 is installed in /usr/local by self. extracting the zip file there. Mar 21, 2018 at 11:43

1 Answer 1

1

When you installed maven, openjdk-8-jre-headless was installed as a dependency. The Java Runtime Environment (jre) does include the java binary, but not the Java compiler (javac). The java binary (or, to be more specific, a link to it) now resides in /usr/bin. Since the PATH-variable is processed left-to-right, executing java executes /usr/bin/java, whereas javac executes /usr/local/jdk-9.0.4/bin/javac because it was not found in any other folder contained in PATH. You can check this yourself using the which command, e.g. which java or which javac.

The openjdk8 jre is most likely installed in /usr/lib/jvm/java-8... and its binaries are linked in /usr/bin by the Debian Alternatives System.

You must log in to answer this question.

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