Install OpenJDK on CentOS and Select the Default Java Runtime
Publication date:
Updated:
INFORMATION > Install OpenJDK on CentOS and Select the Default Java Runtime
Bottom line: Install a supported OpenJDK build from an approved repository, select the system default with alternatives, verify java -version and javac -version, and set JAVA_HOME only for software that actually requires it.
What you'll learn
- The difference between a JRE/runtime command, a full JDK, PATH, and
JAVA_HOME. - How alternatives selects among installed Java commands without hard-coded symlink chains.
- Why Java distribution support and licensing must be checked rather than reduced to “Oracle Java is paid.”
Who this is for: Linux administrators preparing Java for Maven, Tomcat, or another service.
2026 context: The CentOS 7/OpenJDK 8 commands below are historical. Choose a supported JDK line compatible with the application, use current DNF package names, and consult the vendor's support and licensing terms for the exact distribution.
Overview
This historical procedure installs OpenJDK on CentOS 7 and selects the default java command. Java licensing and support depend on the distributor and release; OpenJDK is used here because it was available through the CentOS package repositories.
Table of Contents
1. Legacy installation walkthrough
This section describes the procedure for setting the path from where you download Java.
1-1. Download Materials
Download OpenJDK from the following site
1-2. Thawing and moving materials
Move OpenJDK to the server and unzip it. The following assumes that you have placed OpenJDK under "/var/work".
[root@hostname ~]# tar xzvf /var/work/openjdk-11+28_linux-x64_bin.tar.gz
[root@hostname ~]# mkdir /usr/lib/java
[root@hostname ~]# mv jdk-11 /usr/lib/java/
The above command unzips OpenJDK under "/var/work", creates a "java" folder under "/usr/lib/", and moves the unzipped OpenJDK under "/usr/lib/java/".
1-3. Register commands in alternatives
The alternatives system manages symbolic links for commands that have multiple installed implementations. It does not set an environment variable. Registering a Java executable allows the system-wide java link to be switched between installed runtimes.
[root@hostname ~]# alternatives --install /usr/bin/java java /usr/lib/java/jdk-11/bin/java 1
[root@hostname ~]# alternatives --install /usr/bin/javac javac /usr/lib/java/jdk-11/bin/javac 1
The first line of the above command explains
• A shortcut link to "/usr/bin/java" will be created.
Use java as the link group. Multiple candidate executables can be registered in the same group and selected by priority or administrator choice.
• Set the shortcut destination to "/usr/lib/java/jdk-11/bin/java".
• Assume priority 1.
This will cause the java command to execute
①A shortcut to /usr/bin/java will be invoked. Note: Commands such as "mkdir" and "ls" that are usually executed are also stored under "/usr/bin". The "mkdir" and "ls" commands that you normally use without much thought are invoked here.
②The shortcut destination "/etc/alternatives/java" is called. This is also a shortcut. Note: The "java" in "/etc/alternatives/java" is the value specified by the group name.
③In addition, the shortcut destination "/usr/lib/java/jdk-11/bin/java" is invoked.
The java command is executed in the sequence of ① through ③ above.
Check to see if the java command is enabled with the following command.
[root@hostname ~]# java -version
openjdk version "xx" yyyy-mm-dd
OpenJDK Runtime Environment xx.x (build xx+xx)
OpenJDK 64-Bit Server VM xx.x (build xx+xx, mixed mode)
Confirm that the reported Java version and vendor match the runtime intended for the application.
2. Conclusion
The alternatives system selects the executable reached through the system java link. Applications and services may still use an explicit JAVA_HOME or executable path, so verify the runtime in the actual launch context.
Thank you very much for watching until the end.
Official references
■INFORMATION
■PROFILE
■CONTACT