I have an Ubuntu installation with Oracle JDK 1.8.0_141 that was installed using this guide.

tar file was extracted to /opt/jdk and below commands used to set java as default.

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

java -version command works fine after these have been completed, but when I try to install maven using apt-get it tries to install default-jre rather than using this installed version.

Do you have any idea how I can change this default behavior?

  • The problem is that apt cares about packages, not programs. The formerly recommended way to install Oracle Java was from the webupd8 PPA however I'm not sure if that advice is still current. Otherwise, you could consider using make-jpkg as described here davmail and JAVA INSTALLED MANUALLY (I've never tried this personally). – steeldriver Feb 1 '18 at 12:25

This was solved after setting the kava alternative

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk/jdk1.8.0_144/bin/java" 1

sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk/jdk1.8.0_144/bin/javac" 1

sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/jdk/jdk1.8.0_144/bin/javaws" 1

It still install the default jdk when installing maven. But uses oracle jdk when building.

Thanks for the wikihow page : https://www.wikihow.com/Install-Oracle-Java-JDK-on-Ubuntu-Linux

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.