JDK 12, installation of OpenJDK 12 and Oracle JDK 12 on Ubuntu 19.04

about jdk 12 on Ubuntu 19.04

In the next article we will take a look at how we can install JDK 12 on Ubuntu. Java Development Kit or JDK is a tool for developing Java applications. This will allow users to compile our Java codes, run them, test them and sign them.

Currently we can find 2 versions of JDK. One is called OpenJDK and the other oracle jdk. The first is a project to keep JDK free of Oracle codes. It is an open source implementation of Oracle JDK, which is not open source and has many restrictions.

Install JDK 12 on Ubuntu 19.04

java logo
Related article:
Install Java 8, 9 and 10 on Ubuntu 18.04 and derivatives

OpenJDK 12 installation

We will be able to find OpenJDK 12 available in the official Ubuntu 19.04 package repository. Therefore, we will be able to install it easily with the APT package manager. First we will have to update the cache of the APT package repository with the following command:

sudo apt update

OpenJDK 12 has two versions. A Complete version and a version of headless system. This latest version does not have GUI programming libraries included and requires less disk space.

If you are interested install the full version of OpenJDK 12, run the following command in the terminal (Ctrl + Alt + T):

openjdk installation 12

sudo apt install openjdk-12-jdk

If you are more interested in install headless system version of OpenJDK 12, the command to execute is the following:

Openjdk 12 headless installation

sudo apt install openjdk-12-jdk-headless

After the installation of OpenJDK 12, we can execute the following command to check if OpenJDK is working properly:

openjdk version

java -version

Installing Oracle JDK 12 Using PPA

In Ubuntu 19.04 we will also be able to install Oracle JDK 12. This version of JDK is not available in the official Ubuntu package repository, but we can use the linuxuprising / java PPA to install it.

If we want to add the linuxuprising / java PPA in Ubuntu 19.04, in a terminal (Ctrl + Alt + T) we will only have to execute the command:

add repo linuxsprising

sudo add-apt-repository ppa:linuxuprising/java

After this we can install Oracle JDK 12 typing the command:

install oracle java 12

sudo apt install oracle-java12-installer

During the installation you will have to select “Accept”And press Intro to finish accepting the Oracle Technology Network License Agreement for Oracle Java SE.

Oracle technology license agreement

After the installation, we can check if it is working by typing the following command in terminal:

Oracle java jdk version

java -version

Oracle JDK 12 Installation Using .DEB Package

Another option to install Oracle JDK will download the corresponding .DEB file from the official website. To do so, you will have to visit the Oracle website from the browser. Once on the page you will have to click on the button "Download Java Platform (JDK) 12«.

download oracle jdk 12 .deb file

Tras accept the license agreement, will click the .DEB package file jdk-12.0.1. This is the latest version at the time of writing this article.

accept the license on the Oracle website

The browser will ask us to save the .DEB file. Download finished we will go to the directory ~ / Downloads, or to the folder where you have saved the downloaded package:

cd ~/Descargas

Now we will install the .DEB package as follows:

install .deb jdk file 12

sudo dpkg -i jdk-12.0.1_linux-x64_bin.deb

The next step to follow will be find the path of the bin / directory of the deb package jdk-12.0.1. We will achieve this with the following command:

jdk 12 binary localization

dpkg --listfiles jdk-12.0.1 | grep -E '.*/bin$'

Now we will add JAVA_HOME y we will update the PATH variable with the following command:

update javahome and path variables

echo -e 'export JAVA_HOME="/usr/lib/jvm/jdk-12.0.1"\nexport PATH="$PATH:${JAVA_HOME}/bin"' | sudo tee /etc/profile.d/jdk12.sh

After this, we have reboot our Ubuntu machine with the following command:

sudo reboot now

Once the computer restarts, we can run the following command to check if JAVA_HOME and PATH environment variables are set correctly:

checking java variables

echo $JAVA_HOME && echo $PATH

If everything is correct, we can check if Oracle JDK 12 works correctly typing:

java -version installed from package .deb

java -version

Compiling and Running a Simple Java Program

Once the JDK 12 is installed, the next step will be to write a small and simple Java program to check if we can compile it and run it with OpenJDK 12 or Oracle JDK 12.

To do it we will create a file called TestJava.java and inside we will write the following lines:

example code of a Java program

public class PruebaJava {
       public static void main(String[] args) {
            System.out.println("Hola usuarios Ubunlog");
       }
}

Now for compile the source file TestJava.java In a terminal (Ctrl + Alt + T) we will go to the directory where the file we just created is saved. In this folder we execute the following command:

javac PruebaJava.java

This command should generate a new file called TestJava.class. This is a Java class file and contains Java bytecodes that the JVM (Java VirtualMachine) can execute.

java example build

If everything has been correct, we can run the Java class file TestJava.class As follows:

java example working

java PruebaJava

In the previous command you have to write only the file name without the .class extension. Otherwise it won't work. If all goes well, we will see the expected exit. Therefore, the JavaTest.java program compiled and ran successfully using JDK 12.


A comment, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   alexander said

    Thank you very much, the guide helped me