Skip to main content

Install Java on CentOS 8

Java is one of the most popular programming languages used to build different types of applications and systems.

There are two different implementations of Java, OpenJDK and Oracle Java, with almost no differences between them, except that Oracle Java has a few additional commercial features. Oracle Java License permits only non-commercial use of the software, such as personal use and development use. OpenJDK is an open-source implementation of the Java Platform.

The default CentOS 8 repositories include the latest two major Java LTS versions, Java 8 and Java 11.

In this tutorial, we will explain how to install one or more Java (OpenJDK) versions on CentOS 8 and how to set the default Java via alternatives.

Install OpenJDK 11

If you need only JRE, Install only [java-11-openjdk] package,
but if you need compiler, Install [java-11-openjdk-devel] package, too.

dnf -y install java-11-openjdk java-11-openjdk-devel

cat > /etc/profile.d/ <<‘EOF’
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin

Don’t forget to source the file or logout and back in.

source /etc/profile.d/

java –version

# verify to create test program

# cat > <<'EOF'
class java_test {
    public static void main(String[] args) {
        System.out.println("Hello Java World !");


java java-test

Hello Java World !

alternatives –config java

alternatives –config javac

java –version

javac –version

$ echo $JAVA_HOME
$ echo $PATH

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *