The Java JDK (Java Development Kit) is a software development environment used for developing Java Applications. The JDK is a collection of programming tools, notably JRE (Java Runtime Environment), Java (Loader for Java Application), Javac (Compiler), Jar (Archiver), etc.
JDK or JRE
Contents
Application developers who are new to Java often confuse the Java Development Kit with the Java Runtime Environment. The JDK is a package of tools for developing Java application, whereas the JRE is a package of tools for running Java application.
OpenJDK or Oracle Java
OpenJDK is an open source implementation of the Oracle Java SE platform edition. Oracle develops Oracle Java SE whereas the OpenJDK is developed by Oracle Corporation, OpenJDK and Java Community, Red Hat, Azul Systems, IBM, Apple Inc, and SAP SE.
There is no technical difference between OpenJDK and Oracle JDK.
THIS DOCUMENT IS ALSO AVAILABLE FOR
Install Java on CentOS 8 / RHEL 8
Install OpenJDK or Oracle Java as per your requirement.
You can have multiple versions of Java (OpenJDK and Oracle Java) on your system. But, you can have only one default version of Java.
Install OpenJDK
Installing OpenJDK is a pretty straight forward process in CentOS 8 / RHEL 8.
OpenJDK is available from Red Hat Enterprise Linux 8 for x86_64 – AppStream (RPMs) in RHEL 8.
You can use the yum command to install OpenJDK.
Install OpenJDK JDK
### Java JDK 8 ### yum -y install java-1.8.0-openjdk-devel ### Java JDK 11 ### yum -y install java-11-openjdk-devel
Install OpenJDK JRE
### Java JRE 8 ### yum -y install java-1.8.0-openjdk ### Java JRE 11 ### yum -y install java-11-openjdk
Install Oracle Java
There is no separate JRE (Java Runtime Environment) anymore. Oracle JDK now provides JRE as well.
Download Oracle Java JDK
You can either use the command line or browser to download the JDK.
Go to Oracle JDK page to download packages using the browser. Download the rpm binary package for the easy installation.
Oracle Java JDK 12:
Download Oracle Java 12 (v12.0.2)
Oracle Java JDK 11 (LTS):
Download Oracle Java 11 (v11.0.4) (Login Required)
Oracle Java JDK 8:
Download Oracle Java 8 (v8u221) (Login Required)
If you still want to download through the command line, install the wget package.
yum install -y wget
Then, use the below command to download Oracle Java using the terminal.
### Oracle Java JDK 12 ### wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.2_linux-x64_bin.rpm ### Oracle Java JDK 11 ### LOGIN REQUIRED ### Oracle Java JDK 8 ### LOGIN REQUIRED
Install Oracle Java JDK
Install Oracle Java JDK using the rpm command.
### Oracle Java JDK 12 ### rpm -ivh jdk-12.0.2_linux-x64_bin.rpm ### Oracle Java JDK 11 (LTS) ### rpm -ivh jdk-11.0.4_linux-x64_bin.rpm ### Oracle Java JDK 8 ### rpm -ivh jdk-8u221-linux-x64.rpm
By default, Java JDK is installed in /usr/java/ directory. To install Oracle JDK to a custom directory use rpm -ivh –prefix=/<path>/ rpmfile command.
Set Default Java Version
Use the alternatives command to set the default java version.
alternatives --config java
Select Java:
If your system has multiple Java versions, then the above command would list all Java versions like below.
There are 3 programs which provide 'java'. Selection Command
----------------------------------------------- 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-1.el8_0.x86_64/jre/bin/java) 2 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.2.7-2.el8.x86_64/bin/java)
*+ 3 /usr/java/jdk-12.0.2/bin/java Enter to keep the current selection[+], or type selection number: 2
Enter the number below selection column to set the default Java version.
Here, I chose 2 for OpenJDK 11.
Verify Java Version
Check the java version using the following command.
java -version
Output:
openjdk version "11.0.2" 2019-01-15 LTS OpenJDK Runtime Environment 18.9 (build 11.0.2+7-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+7-LTS, mixed mode, sharing)
The output may vary depending upon the package and the version you chose it to be the default 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.
vi /etc/profile.d/java.sh
Set variables based on the Java location and version.
export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-11.0.2.7-2.el8.x86_64/bin/ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.2.7-2.el8.x86_64/ export J2SDKDIR=/usr/lib/jvm/java-11-openjdk-11.0.2.7-2.el8.x86_64/
Load the environments into the current session.
source /etc/profile.d/java.sh
To set the environment variables for a particular user, place the above variables in ~/.bash_profile file.
Conclusion
I hope, this post helped you install Java on your RHEL 8 system. Java is a must to run applications such as Tomcat, Gradle, ELK Stack, Graylog, Eclipse IDE, Hadoop, etc.