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/java.sh <<‘EOF’
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which java)))))
export PATH=$PATH:$JAVA_HOME/bin
EOF

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

source /etc/profile.d/java.sh

java –version

# verify to create test program

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

javac java-test.java

java java-test

Hello Java World !

alternatives –config java

alternatives –config javac

java –version

javac –version

$ echo $JAVA_HOME
$ echo $PATH
$ echo $CLASSPATH

Vincent Verloop

Ervaren ICT Professional met een bewezen geschiedenis van werken in de IT. Begonnen in eigen computer werkplaats, daarna aan het werk gegaan bij KPN als technische helpdeskmedewerker. Daarna Ziggo monteur. Daarna systeembeheerder bij Rijksdienst voor Wegverkeer. Daarna Zelfstandig Ondernemer. Daarna Sport Computer Graphics. Daarna T-Mobile/Tele2. Daarna Centric. Bekwaam in OS X, Search Engine Optimization (SEO), PHP, WordPress en Domain Name System (DNS). Sterke media- en communicatieprofessional met een diploma MBO niveau 4 gericht op ICT-beheer / ICT-beheerder. Volg Vincent Verloop op Twitter.

Leave a Reply

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

BLIJF OP DE HOOGTE
Schrijf u in voor onze gratis nieuwsbrief


© Vincent Verloop. All rights reserved. Powered by Verloophosting.