Home > Blockchain >  resolve different java and javac version in ubuntu
resolve different java and javac version in ubuntu

Time:01-20

My java --version gives:

openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13 8-Ubuntu-0ubuntu1.21.10)
OpenJDK 64-Bit Server VM (build 11.0.13 8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)

But when I do: javac --version I get:

javac 17

whereis java gives:

java: /usr/bin/java /usr/share/java /opt/jdk-17/bin/java /usr/share/man/man1/java.1.gz

As far as I can remember I downloaded openjdk 17 from the official site and followed official documentation.

I usually work with maven projects and I just noticed this issue. Haven't created any problem so far. But I would like to resolve it. Is it possible to do so without removing java and reinstalling?

Update:

echo $PATH
/home/arnob/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/opt/jdk-17/bin:/home/arnob/sdks/flutter/bin:/opt/maven/bin:/home/arnob/.local/bin:/home/arnob/.pub-cache/bin:/usr/lib/postgres/13/bin

And

ls -l /usr/bin/java

lrwxrwxrwx 1 root root 22 Dec 19 00:58 /usr/bin/java -> /etc/alternatives/java

CodePudding user response:

In your bashrc, for example, seems like you're adding /opt/jdk-17/bin to the PATH, but at the end, not before /usr/bin/, and you have Java 11 JRE installed separately, so it gets picked up first

You should fix this by reversing it

export JAVA_HOME=/opt/jdk-17
export PATH="${JAVA_HOME}/bin;$PATH"

I suggest doing the same thing for flutter, maven, Postgres, etc

CodePudding user response:

Run the below commands in your terminal and choose the default java and javac version. You needn't uninstall anything.

update-alternatives --config java
update-alternatives --config javac
  •  Tags:  
  • Related