# Install Java on CentOS 8

# Install OpenJDK

You can use the yum command to install OpenJDK.

yum -y install java-11-openjdk-devel

Check the java version using the following command.

java -version

# Setup Environmental Variables

The most important part has come now, Java applications often require JAVA environment variables to be set in the system.

Create a new file under /etc/profile.d directory

sudo nano /etc/profile.d/java.sh

Set variables based on the Java location and version.

export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-
export J2SDKDIR=/usr/lib/jvm/java-11-openjdk-

Load the environments into the current session.

source /etc/profile.d/java.sh