
Java is the popular programming language in the world. It is owned by Oracle and used to build different kinds of applications. This tutorial describes how to install various versions and implementations of Java on CentOS 8. We’ll show you how to install OpenJDK as well as Oracle Java. OpenJDK is an open-source implementation of the Java Platform while you can use Oracle Java only for non-commercial purpose, such as personal use and development use.
Default CentOS 8 repositories includes Java 8 and Java 11 Java LTS versions.
Installing OpenJDK 11
It is always recommended to install the latest Java LTS (JDK 11) version. Run the following command to install the OpenJDK 11 on CentOS 8. Make sure that you are login as root or user with sudo privileges:
sudo yum install java-11-openjdk-devel
Now verify the installation by typing :
java -version
The output should display as given below:
openjdk version "11.0.4" 2019-07-16 LTS OpenJDK Runtime Environment 18.9 (build 11.0.4+11-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.4+11-LTS, mixed mode, sharing)
Alright! You have successfully installed Java on your CentOS 8 machine.
You also can install headless version of OpenJDK which have minimal Java runtime which used where not need of graphical user interface. This version is more convenience for server applications due to fewer dependencies and uses less system resources.
Execute below command to install headless OpenJDK 11:
sudo yum install java-11-openjdk-headless
Installing OpenJDK 8
Java 8 is most widely used LTS version of Java and will be supported untill March 2025. Some of applications requires specific version of JDK. You can install Java 8 by typing below command:
sudo yum install java-1.8.0-openjdk-devel
Once the installation complete verify the installation by checking the Java version:
java -version
It will show output as below:
openjdk version "1.8.0_222" OpenJDK Runtime Environment (build 1.8.0_222-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
Setting the Default Java Version
If your system have multiple verions of Java on your CentOS system, you can set default Java version to use default when you type java
in the terminal.
First of all, check current default version by typing:
java -version
Run the alternatives
command to set up default version:
sudo alternatives --config java
It will show all the installed Java versions as below:
Selection Command 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.4.11-0.el8_0.x86_64/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el8_0.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number:
There are 2 programs which provide ‘java’. Select the number of the version you want to use as the default and hit Enter.
You can also change javac (compiling Java programs) version using below command:
sudo alternatives --config java
Conclusion
CentOS 8 supports Java 8 and Java 11 LTS versions, you can install using yum package manager on your CentOS system.
Leave a Reply