2

I tried to install java 11 with the command,

apt-get install openjdk-11-jdk

install was completed, but I still got this result from java -version command

$ java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 8.0.6.5 - pxa6480sr6fp5-20200111_02(SR6 FP5))
IBM J9 VM (build 2.9, JRE 1.8.0 Linux amd64-64-Bit Compressed References 20200108_436782 (JIT enabled, AOT enabled)
OpenJ9   - 7d1059c
OMR      - d059105
IBM      - c8aee39)
JCL - 20200110_01 based on Oracle jdk8u241-b07

However, I got version 11 when check javac

$ javac -version
javac 11.0.7

I searched for the solutions, and tried this command below, but I didn't work well. (It did not show any output at all and just being stopped for hours)

$ sudo add-apt-repository ppa:openjdk-r/ppa

How can I solve this problem? I use ubuntu mint bionic

Maria__
  • 39
  • 5

1 Answers1

3

You may use update-java-alternative command to check and update the java versions installed on your system To list all the installed versions :

update-java-alternatives --list

To use other version as the default java version:

sudo update-java-alternatives --set /path/to/new-java-version

The /path/to/new-java-version you can get from the fist command

If the command update-java-alternatives(the preferred way for debian based systems) is not available then use sudo update-alternatives --config java

Also to change the JAVA_HOME you have to run : source /etc/environment after editing the /etc/environment file by appending/editing following variable

JAVA_HOME="/path/to/new-java-version"

Also make sure that if you have setup these values in .bashrc or .profile of any user, replace them with same values

JAVA_HOME="/path/to/new-java-version"

and then run source .bashrc or source .profile

You can refer to this as well https://linuxize.com/post/install-java-on-ubuntu-18-04/ which is using update-alternatives

vik
  • 151
  • 4