Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install the latest openjdk 12 on Ubuntu 18.04

I've installed the default jdk by issuing the command:

apt-get install default-jdk

This will install openjdk 11 and apt-get seems to install the files all over the place. Examples:

/etc/java-11-openjdk/management
/usr/lib/jvm/java-11-openjdk-amd64/lib
/usr/share/doc/openjdk-11-jre-headless/JAVA_HOME
/var/lib/dpkg/info/openjdk-11-jre:amd64.postinst

As you can see by the example locations above, there are files scattered everywhere.

I've just installed a web app that's giving a warning that it only supports jdk 12 (I think it's the latest openjdk version). How can I install version 12 so that it replaces version 11? What is the best way to upgrade the openjdk version on Ubuntu 18.04 so that it doesn't mingle with the previous version?

like image 849
u84six Avatar asked May 02 '19 14:05

u84six


1 Answers

This works for me:

  1. Download archive with wget or go to the JDK 12 GA Release site and download the archive manually:
wget https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz
  1. Create the /usr/java directory:
sudo mkdir /usr/java
  1. Move archive to the new directory:
mv openjdk-12.0.2_linux-x64_bin.tar.gz /usr/java
  1. Go to this directory:
cd /usr/java
  1. Unpack archive:
sudo tar -xzvf openjdk-12.0.2_linux-x64_bin.tar.gz
  1. Set the environment variables, for this open the /etc/profile file:
sudo nano /etc/profile
  1. And add the following code to the end of this file:
JAVA_HOME=/usr/java/jdk-12.0.2
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
  1. Configure Java commands to use the newly JDK by default:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-12.0.2/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-12.0.2/bin/javac" 1
  1. Check Java version:
java -version

If you previously had another version of Java installed and the version has not changed, try to run the following command and to select the desired version:

sudo update-alternatives --config java
like image 98
ns16 Avatar answered Oct 18 '22 01:10

ns16