You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

In our today’s guide, we’ll talk about how to install Java 14 / OpenJDK 14 on CentOS 7/8 & Fedora 32/31/30/29. Java 14 is now available for general usage – Check out General Availability release notes for new features. Production-ready binaries are also available from Oracle for Java SE Development Kit 14.

JDK 14 is the open-source reference implementation of version 14 of the Java SE Platform as specified by by JSR 388 in the Java Community Process. Install JDK | OpenJDK 14 on your CentOS 8/7 & Fedora 32/31/30/29 by following the steps below.

For Ubuntu / Debian, use: Install Oracle Java 14 (OpenJDK 14) on Ubuntu & Debian

Option 1: Install OpenJDK 14 on CentOS 8/7 & Fedora 32-28

Visit JDK 14 releases page to download the latest archive.

sudo yum -y install curl
curl -O https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz

Extract the downloaded OpenJDK 14 archive file using tar command.

tar xvf openjdk-14_linux-x64_bin.tar.gz

Move the resulting folder to /opt directory.

sudo mv jdk-14 /opt/

Configure Java environment:

sudo tee /etc/profile.d/jdk14.sh <<EOF
export JAVA_HOME=/opt/jdk-14
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file and check java command

source /etc/profile.d/jdk14.sh

Confirm Java version.

$ echo $JAVA_HOME
/opt/jdk-14

$ java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

Option 2: Install Java SE Development Kit 14 on CentOS 8/7 & Fedora 31-29

If you choose to go with Java SE Development Kit 14, download RPM package for CentOS / RHEL / Fedora system using the command below.

curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"https://download.oracle.com/otn-pub/java/jdk/14+36/076bab302c7b4508975440c56f6cc26a/jdk-14_linux-x64_bin.rpm"

Then install the RPM package using the yum or rpm command.

$ sudo rpm -Uvh jdk-14_linux-x64_bin.rpm
warning: jdk-14_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                                                            (10################################# [100%]
Preparing...                                                            (10################################# [100%]
Updating / installing...
   1:jdk-14-2000:14-ga                ################################# [100%]

Confirm Java version installed

$ java -version
java version "14" 2020-03-17
Java(TM) SE Runtime Environment (build 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

Configure Java environment.

cat <<EOF | sudo tee /etc/profile.d/jdk14.sh
export JAVA_HOME=/usr/java/default
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

To use Java Home, source the file.

source /etc/profile.d/jdk14.sh

Test Java Installation

Create a HelloWorld Java program.

$ vi HelloWorld.java 
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}

Compile Java code.

$ javac HelloWorld.java

Run your Java program.

$ java HelloWorld
Hello, World

Choosing Default Version of Java

If you have more than one version of Java installed, you can set default one using alternatives command.

sudo alternatives --config java

Select Java to set as default.

$ sudo alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-14/bin/java

Enter to keep the current selection[+], or type selection number: 

Recommended books:

Best Java Development Books to read

Enjoy your Java Development on a Linux machine and check other related guides in our blog.

Install Node.js on CentOS 8

Install Ruby on CentOS 8

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF