0

I am trying to install ANT after installing java. My java in Sun Java.

pc19@pc19-H110:~$  java -version
java version "20.0.2" 2023-07-18
Java(TM) SE Runtime Environment (build 20.0.2+9-78)
Java HotSpot(TM) 64-Bit Server VM (build 20.0.2+9-78, mixed mode, sharing)

pc19@-H110:~$ echo $JAVA_HOME
/usr/lib/jvm/jdk-20/bin/java

pc19@pc19-H110:~$ whereis java
java: /usr/bin/java /usr/share/java /usr/lib/jvm/jdk-20/bin/java

pc19@-H110:~$ sudo apt-get install ant

pc19@-H110:~$ java -version
openjdk version "11.0.20.1" 2023-08-24
OpenJDK Runtime Environment (build 11.0.20.1+1-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.20.1+1-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)

When I install ANT using sudo apt get install ant, it is overring the Sun Java insallation with OpenJdk installation. Does anybody know the workaround for it?

Why is ant installation overriding java? How do I stop it?

Max
  • 705
  • 1
  • 7
  • 14

1 Answers1

0

The package manager is unaware of your Oracle Java installation. The ant package requires a JRE, and depends on either the default-jre-headless or the java8-runtime-headless package. As a result, installing ant installs the default JRE, which is OpenJDK 11 on Ubuntu 20.04 (apt install ant would tell you this). The JRE package reconfigures /usr/bin/java, and since that comes before your jdk-20/bin directory, java runs the system JRE rather than your JRE.

To avoid installing OpenJDK 11, you can tell your system that there is a headless JRE installed by creating a dummy default-jre-headless package; see How to make apt ignore unfulfilled dependencies of installed package? for details, replacing gstreamer0.10-plugins-good with default-jre-headless.

Stephen Kitt
  • 434,908