1

I am trying to install java version SE12 form respective tar.gz file. I followed this thread right here, How to set Oracle's Java as the default Java in Ubuntu? (@Barracuda's answer).

When I am trying to execute the following command:

sudo update-alternatives --install /usr/bin/java java ${JAVA_HOME%*/}/bin/java 20000

I am getting following error:

update-alternatives: error: alternative path /usr/java/jdk-12.0.2/bin/java doesn't exist

But ~/usr/java/jdk-12.0.2/bin/java does exist! I don't understand why the error is occurring. Hope someone would help me.

Thanks in advance !


Added part:

The above issue is solved by changing the path in $JAVA_HOME. I followed the steps in the thread to install java. Finally when I check java version it still shows java 11.

When I tried to choose java 12 as default,

sudo update-alternatives --config java

I got the following output:

There are 4 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /home/ubuntu/usr/java/jdk-12.0.2/bin/java        20000     auto mode
  1            /home/ubuntu/miniconda3/envs/vino/bin/java       20000     manual mode
  2            /home/ubuntu/usr/java/jdk-12.0.2/bin/java        20000     manual mode
  3            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  4            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Java 12 is already selected, but when I check java version:

java -version

this is what I get:

openjdk version "11.0.15-internal" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15-internal+0-adhoc..src)
OpenJDK 64-Bit Server VM (build 11.0.15-internal+0-adhoc..src, mixed mode)

Please help me with this.

  • in your question there is a difference between the path in the error message and the path you stated that exists: the leading `/`. The error message gives an absolute path, starting at root (`/`) while you were giving a relative path, but didn't write, what your working directory is, when you check it. How do you check the existence of the path and what is your working directory at that time? (You check the latter with `pwd` - print working directory.) – cyberbrain Jul 18 '22 at 05:58
  • After your edit: `/usr/java/jdk-12.0.2/bin/java` and `~/usr/java/jdk-12.0.2/bin/java` are **not** the same path. The second one is under your home directory. Fix your `JAVA_HOME` accordingly. – Federico klez Culloca Jul 18 '22 at 07:01
  • i just edited the path to show that folder is made in home folder. Did the same for $JAVA_HOME also. It worked. – Sowmya Pulapet Jul 18 '22 at 07:06

0 Answers0