Downloading and Installing JDK on Linux

This section provides a tutorial example on how to download and install JDK on Linux systems. The best way to install JDK on CentOS system is to the 'yum' package management tool.

Downloading and installing JDK on a Linux computer is more difficult for several reasons:

1. There are many variations and versions of Linux platforms running on different system architectures. So there is no single JDK package that works perfectly on all Linux platforms.

2. Oracle offers 3 binary packages for all Linux platforms with some installation instructions:

Package                    Platforms
-------                    -------
Linux Debian Package       Debian
Linux RPM Package          Red Hat and SuSE
Linux Compressed Archive   Generic

3. OpenJDK offers a single generic binary package for all Linux platforms.

If you try to install the generic binary package on your specific Linux platform, you most likely will encounter some issues.

The best way to install JDK on your specific Linux platform is to use the package management tool on the system to search and automatically install the OpenJDK binary package that was built specifically for your platform.

Here is what did to on my CentOS system with the "yum" package management tool to search for openJDK, logging in as "root":

herong# yum search openJDK

java-1.6.0-openjdk.i686 : OpenJDK Runtime Environment
java-1.6.0-openjdk-devel.i686 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.i686 : OpenJDK API Documentation
java-1.6.0-openjdk-src.i686 : OpenJDK Source Bundle
...
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle

So the latest version for my platform is OpenJDK 1.8, divided into several parts. To install JDK with compiler and other tools, I need to install java-1.8.0-openjdk.i686 and java-1.8.0-openjdk-devel.i686:

herong# yum install java-1.8.0-openjdk
...
Installed:
  java-1.8.0-openjdk.i686 1:1.8.0.232.b09-1.el6_10

herong# yum install java-1.8.0-openjdk
...
Installed:
  java-1.8.0-openjdk-devel.i686 1:1.8.0.232.b09-1.el6_10

Now verify the installation:

herong# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK Server VM (build 25.232-b09, mixed mode)

herong# javac -version
javac 1.8.0_232

Finally, set the JAVA_HOME environment variable, so other applications can find where JDK is installed. This can be done with an "export" command.

herong# export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.i386

Congratulations, you have successfully installed JDK on your Linux system!

Table of Contents

 About This Book

JDK - Java Development Kit

 Downloading and Installing JDK on Mac

 Downloading and Installing JDK on Windows

 Adding JDK "bin" Directory to Path Setting

Downloading and Installing JDK on Linux

 Writing My First Java Program

 JDK Documentation Installation

 Execution Process, Entry Point, Input and Output

 Primitive Data Types and Literals

 Control Flow Statements

 Bits, Bytes, Bitwise and Shift Operations

 Managing Bit Strings in Byte Arrays

 Reference Data Types and Variables

 Enum Types and Enum Constants

 StringBuffer - The String Buffer Class

 System Properties and Runtime Object Methods

 Generic Classes and Parameterized Types

 Generic Methods and Type Inference

 Lambda Expressions and Method References

 Java Modules - Java Package Aggregation

 Execution Threads and Multi-Threading Java Programs

 ThreadGroup Class and "system" ThreadGroup Tree

 Synchronization Technique and Synchronized Code Blocks

 Deadlock Condition Example Programs

 Garbage Collection and the gc() Method

 Assert Statements and -ea" Option

 Annotation Statements and Declarations

 Java Related Terminologies

 Archived Tutorials

 References

 Full Version in PDF/EPUB