Learn how to install Java on CentOS 8 with our comprehensive guide. Follow step-by-step instructions to set up the latest Java Development Kit (JDK) and Runtime Environment (JRE) on your CentOS 8 server. #centlinux #linux #java
Table of Contents
What is Java?
Java is a widely-used programming language and computing platform originally developed by Sun Microsystems (now owned by Oracle Corporation). Here are some key aspects of Java:
Key Features of Java
- Platform Independence: Java programs can run on any device or operating system that has a Java Virtual Machine (JVM) installed, making it highly portable.
- Object-Oriented Programming: Java is based on object-oriented programming principles, which include encapsulation, inheritance, and polymorphism.
- Security: Java emphasizes security with features like bytecode verification and a security manager to protect systems from malicious code.
- Rich API: Java provides a vast standard library (Java API) that includes utilities for networking, I/O, database connection, and more.
- Multi-threading: Java supports multi-threading, allowing concurrent execution of multiple tasks within a program.
- Automatic Memory Management: Java uses automatic garbage collection to manage memory, freeing developers from manually allocating and deallocating memory.
- Scalability: Java applications are scalable and can handle large-scale enterprise-level applications.
Common Uses of Java
- Enterprise Applications: Java is widely used for building enterprise-scale applications, including banking systems, e-commerce platforms, and customer relationship management (CRM) software.
- Web Development: Java Enterprise Edition (Java EE) is used for developing web applications, web services, and dynamic websites.
- Mobile Applications: Android apps are primarily developed using Java (though Kotlin is also now a preferred language).
- Big Data Technologies: Java is used in big data technologies like Apache Hadoop, Apache Spark, and Apache Kafka for processing and analyzing large volumes of data.
- Desktop GUI Applications: Java Swing and JavaFX are used for developing desktop graphical user interface (GUI) applications.
Java Ecosystem
Java has a vibrant ecosystem with tools, frameworks, and libraries that enhance development productivity and efficiency. Key components of the Java ecosystem include:
- Integrated Development Environments (IDEs): Eclipse, IntelliJ IDEA, and NetBeans.
- Build Tools: Apache Maven and Gradle for automating build processes.
- Frameworks: Spring Framework, Hibernate, and Apache Struts for building scalable and modular applications.
- Testing Frameworks: JUnit and TestNG for unit testing.
Conclusion
Java’s versatility, platform independence, and extensive ecosystem make it a popular choice for a wide range of applications, from mobile and web development to enterprise systems and big data processing.
If you’re interested in learning more about Java or need assistance with Java installation on CentOS 8, feel free to reach out!
Recommended Training: Java Masterclass 2025: 130+ Hours of Expert Lessons from Tim Buchalka
Environment Specification
In this setup, we are using a virtual machine (VM) running a minimally installed CentOS 8 server. This means that the system has only the essential packages installed, without any graphical user interface (GUI) or additional software. A minimal installation ensures a lightweight, secure, and customizable environment, making it ideal for server deployments. The virtual machine is configured with the necessary CPU, RAM, and storage resources to efficiently run CentOS 8 and any additional software installed later, such as Java.
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – CentOS Linux 8
- Hostname – java-01.sysadminlabs.com
- IP Address – 192.168.116.206 /24
Read Also: How to install Java on Rocky Linux 9
Install OpenJDK on CentOS 8
OpenJDK (Open Java Development Kit) is a free and open-source implementation of the Java Platform, Standard Edition (Java SE). It serves as the reference implementation for Java SE and is widely used for running Java-based applications in both development and production environments.
OpenJDK is maintained by Oracle along with contributions from the open-source community and other organizations. It is distributed under the GNU General Public License (GPL) v2, making it a preferred choice for developers who need a vendor-neutral, stable, and fully compatible Java runtime environment without licensing restrictions.
Two versions of OpenJDK are available in CentOS 8 standard yum repositories. i.e. OpenJDK 8 and OpenJDK 11. Obviously, they are the open source implementations of Oracle Java SE 8 and Oracle Java SE 11.
The installation steps are same for both versions. Here, we are installing OpenJDK 8 on our Linux server, but you can also install OpenJDK 11 by following the same steps.
Connect with java-01.sysadminlabs.com as root user by using a ssh client and install OpenJDK java runtime environment.
# dnf install -y java-1.8.0-openjdk.x86_64
We have installed OpenJDK Java Runtime Environment (JRE). Similarly, we can also install Java Development Kit (JDK) by installing package java-1.8.0-openjdk-devel.x86_64.
Define JAVA_PATH environment variable in /etc/profile file, so it can be set automatically when a login shell is initialized.
# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64" >> /etc/profile
Also set the JAVA_PATH for the current shell.
# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-2.el8_1.x86_64
Verify Java version.
# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
OpenJDK Java runtime environment has been installed on CentOS 8.
Install Java on CentOS 8
Oracle Java is the proprietary distribution of Java platform. Oracle Java is available in Standard (SE), Enterprise (EE) and Micro Editions (ME).
Oracle Java SE is the default choice for most of the environments. Here, we are also installing the Oracle Java 13 SE, that is recently released.
Oracle Java SE 13 is available to download at Oracle website.
You are required to have an Oracle User Account for downloading Oracle Java SE 13 RPM. Therefore, Sign up for a free Oracle User Account, then Sign in to Oracle website by using it.
Transfer the downloaded file to java-01.sysadminlabs.com by using WinSCP.
Connect to java-01.sysadminlabs.com as root user by using a ssh tool such as PuTTY.
You can install Oracle Java SE 13 by using dnf command.
# dnf install -y jdk-13.0.2_linux-x64_bin.rpm
Define JAVA_PATH environment variable in /etc/profile file, so it can be automatically set when a login shell is initialized.
# echo "export JAVA_HOME=/usr/java/jdk-13.0.2" >> /etc/profile
Also set the JAVA_PATH for the current shell.
# export JAVA_HOME=/usr/java/jdk-13.0.2
Verify Java version.
# java -version
java version "13.0.2" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
We have successfully installed Oracle Java SE 13 on Linux server.
Install Multiple Java Runtime Environments
We have installed OpenJDK Java 8 and Oracle Java SE 13 on the same Linux server.
Both of these Java versions are available on the CentOS 8 server, but only one is set as default java runtime environment.
Since, we have installed Oracle Java SE 13 after OpenJDK 8. Therefore, we are now running the Oracle Java SE 13 as default java runtime environment.
To switch to OpenJDK 8, we can use the alternatives command.
# alternatives --config java
There are 2 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.232.b09-2.el8_1.x86_64/jre/bin/java)
*+ 2 /usr/java/jdk-13.0.2/bin/java
Enter to keep the current selection[+], or type selection number: 1
We have set the OpenJDK 8 as default Java runtime environment.
Verify the version of Java now.
# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
You can see that, OpenJDK 8 has been set as our default Java runtime environment.
Installation of Java runtime environment on CentOS 8 has been completed successfully.
Final Thoughts
Installing Java on CentOS 8 is a crucial step for anyone looking to develop or run Java applications on a robust server environment. With the right setup, you can leverage Java’s powerful features for a variety of projects, from web applications to enterprise solutions.
Need expert AWS and Linux system administration? From cloud architecture to server optimization, I provide reliable and efficient solutions tailored to your needs. Hire me on Fiverr today!
If you have any questions or need additional help, feel free to reach out!
FAQs
1. What are the available Java versions for CentOS 8?
CentOS 8 supports both OpenJDK (open-source) and Oracle JDK (proprietary). OpenJDK is the default Java version in CentOS repositories, while Oracle JDK requires manual installation from the official website.
2. How can I check if Java is already installed on CentOS 8?
You can verify the installed Java version using a terminal command. If Java is not installed, the system will prompt that the command is not found.
3. Should I install OpenJDK or Oracle JDK?
OpenJDK is recommended for most users as it is open-source, regularly updated, and included in CentOS repositories. Oracle JDK is preferred for enterprise environments that require long-term support and additional features.
4. How do I set the default Java version if multiple versions are installed?
If multiple Java versions are installed, you can use an update command to set the default Java version for system-wide use. This allows you to switch between different installed versions.
5. What should I do after installing Java on CentOS 8?
After installation, verify the Java version, set up environment variables if needed, and configure Java-based applications to ensure they recognize the installed Java runtime.