How to Install Java on CentOS 8
Choose a different version or distribution
Introduction
Before we begin talking about how to install Java on CentOS 8. Let's briefly understand - What is Java?
Java is a widely-used programming language, known for its versatility and compatibility.
This tutorial will provide you with step-by-step instructions on how to install Java on CentOS 8, allowing you to run Java applications and develop Java-based software efficiently. We will also address a few FAQs on how to install Java on CentOS 8.
Advantages of Installing Java on CentOS 8
- Platform Independence: Java applications can run on any platform that supports Java, including CentOS 8.
- Large Ecosystem: Java has a vast ecosystem with a wide range of libraries, frameworks, and tools for various purposes, such as Java Enterprise Edition (EE), Spring, Apache Maven, and more.
- Stability and Reliability: Java is renowned for its stability and reliability. It undergoes rigorous testing before release, ensuring robustness for enterprise-grade applications.
- Performance Optimization: The Java Virtual Machine (JVM) optimizes Java code during runtime, resulting in efficient and performant applications.
- Widespread Usage and Industry Demand: Java is one of the most widely-used programming languages globally.
Prerequisites
- Remember to log in as a user with the sudo privileges.
The Java variations
Java has three different editions which are distributed: The Standard Edition (SE), The Enterprise Edition (EE), and The Micro Edition (ME). Here we will proceed with installing Java SE (Standard Edition).
The two main implementations of Java are OpenJDK and Oracle Java. These are almost similar to one another except for the fact that Oracle Java has a few additional commercial features.
Ubuntu repositories have two different Java packages: Java Runtime Environment (JRE), and the Java Development Kit (JDK).
JRE consists only of the Java Runtime Environment, which is apt for running Java programs. JDK on the other hand includes development/debugging tools and libraries which are suitable for Java developers.
In case you don't know which Java version to use, you should stick to the default OpenJDK version available for CentOS 7.
Installing OpenJDK
OpenJDK is the open-source implementation of Java-Platform. Further, it is the default Java development and runtime in CentOS 8.
Step 1 - Installing the OpenJDK-11 JDK
1) OpenJDK 11 is the current LTS version of Java and recommendation as well. You can install it with yum
using the below command:
sudo yum install java-11-openjdk-devel
2) After that, verify the installation. You will do it by running the below command. It will print the Java version:
java -version
The output will look like this:
openjdk version "11.0.3" 2021-10-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3+7-LTS, mixed mode, sharing)
You now have a successful installation of Java on your CentOS system.
Installing the OpenJDK 17 JRE
Now, install OpenJDK 17 JRE with yum
using the below command:
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
sudo rpm -ivh jdk-17_linux-x64_bin.rpm
Step 2 - Installing OpenJDK 8 JDK
1) Java 8 is the most used version of Java. If your application needs the older Java 8 installation on your CentOS 7 system, then use the below command:
sudo yum install java-1.8.0-openjdk-devel
Step 3 - Installing OpenJDK 8 JRE
1) The Oracle packages are available to download from their official website. Before installing Oracle Java, make sure to read the Oracle JDK License.
2) You will download Oracle Java .rpm
packages from the Java SE Downloads page. To download Oracle Java, you will register on the Oracle site.
3) After, downloading the package. Use the below command to install:
sudo yum localinstall jre-VERSION-linux-x64.rpm
Step 4 - Setting Up the Default Version
1) You can check the default Java version using the below command:
java -version
You will see the below output:
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)
2) If you have multiple Java version installations on the server, you can change the default version using the alternatives
system utility:
sudo alternatives --config java
The output will look similar:
Output
There are 3 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.18.0.9-0.3.ea.el8.x86_64/bin/java)
*+ 2 /usr/lib/jvm/jdk-17-oracle-x64/bin/java
3 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-3.el8.x86_64/jre/bin/java)
Enter to keep the current selection[+], or type selection number:
3) You can simply enter the number and hit Enter
to change the default Java version.
Step 5 - Uninstalling the Java
1) So, if you want to uninstall the Java package, you can do it with yum
. For instance, to uninstall the java-1.8.0-openjdk-devel
package, just run:
sudo yum remove java-1.8.0-openjdk-devel
FAQs to Install Java on CentOS 8
What is the recommended method to install Java on CentOS 8?
The recommended method to install Java on CentOS 8 is by using the OpenJDK package, the open-source implementation of the Java platform.
What are the prerequisites for installing Java on CentOS 8?
To install Java on CentOS 8, you should have a CentOS 8 machine or server with administrative privileges. No previous installations of Java are required.
Can I install other Java versions or Oracle JDK instead of OpenJDK?
Yes, it is possible to install different versions of Java or use the Oracle JDK. However, the process may differ from installing OpenJDK, and you might need to download installation packages from the respective sources or set up repositories.
Why is it recommended to install OpenJDK on CentOS 8?
Installing OpenJDK on CentOS 8 is recommended due to its open-source nature, community support, regular updates, and compatibility with the Java platform.
Can I install multiple versions of Java on CentOS 8?
Yes, it is possible to install multiple versions of Java on CentOS 8. You can have different Java versions coexisting on the same machine, and then configure your system environment variables to use the desired version for specific applications.
Can I update Java to a newer version on CentOS 8?
Yes, you can update Java on CentOS 8 by following the appropriate installation or update process for the Java version you desire.
Are there any security considerations when installing Java on CentOS 8?
Java has a strong security model, and both OpenJDK and Oracle JDK regularly release security updates to mitigate vulnerabilities.
Conclusion
Installing Java on CentOS 8 provides you with a powerful and versatile platform for developing and running Java applications.
By using the recommended method of installing OpenJDK, you can take advantage of the stability, performance, and extensive ecosystem offered by Java.
We hope this detailed tutorial helped you to install Java on CentOS 8.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.