The Ultimate Guide to Installing Java on Linux: RHEL, Ubuntu, and Amazon Linux
Madhukar Beema
Observability | DevSecOps & People-Centric Automation Enabler | AWS Certified Solutions Architect & DevOps Engineer | CISSP, F5 BIG-IP, & Tibco Certified
Introduction
Java remains a fundamental component of enterprise applications, powering everything from microservices to large-scale data processing. This guide provides a technical, detailed approach to installing Java across RHEL (Red Hat Enterprise Linux), Ubuntu, and Amazon Linux, focusing on best practices for manual installation using extracted archives and symbolic links. Additionally, it includes an introduction to Java's core concepts, including classes, modules, and package management.
1. Understanding Java Basics
Before diving into installation, it’s important to understand Java’s core components:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
module my.module {
exports com.example.mymodule;
}
package com.example;
public class MyClass {
// Class implementation
}
Understanding these fundamentals will help developers efficiently structure and maintain their Java applications.
2. OpenJDK vs. Oracle JDK: Which One to Choose?
There are multiple Java distributions available today. Here’s a comparison of the most commonly used ones:
For RHEL-based systems, Red Hat OpenJDK is recommended due to better integration and enterprise support. For Ubuntu and other Debian-based systems, Amazon Corretto offers stability and long-term support.
3. Installing Java on Ubuntu (Debian-based Systems)
3.1 Manual Installation Using Extracted Archive (Recommended Method)
wget https://corretto.aws/downloads/latest/amazon-corretto-17-x64-linux-jdk.tar.gz
sudo mkdir -p /opt/java
sudo tar -xvzf amazon-corretto-17-x64-linux-jdk.tar.gz -C /opt/java
sudo ln -sfn /opt/java/amazon-corretto-17 /usr/lib/jvm/java-17
echo "export JAVA_HOME=/usr/lib/jvm/java-17" >> ~/.bashrc
echo "export PATH=$JAVA_HOME/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
java -version
4. Installing Java on RHEL (Red Hat Enterprise Linux) & CentOS
4.1 Manual Installation Using Extracted Archive (Recommended Method)
wget https://developers.redhat.com/content-gateway/rest/mirror/pub/openjdk/17.0.2/openjdk-17.0.2_linux-x64_bin.tar.gz
sudo mkdir -p /opt/java
sudo tar -xvzf openjdk-17.0.2_linux-x64_bin.tar.gz -C /opt/java
sudo ln -sfn /opt/java/jdk-17.0.2 /usr/lib/jvm/java-17
echo "export JAVA_HOME=/usr/lib/jvm/java-17" >> ~/.bashrc
echo "export PATH=$JAVA_HOME/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
java -version
5. Conclusion
Recommendations:
This guide ensures a production-ready Java setup across Ubuntu, RHEL, and Amazon Linux. Stay tuned for the next article on OpenJDK vs. Oracle JDK licensing and performance comparisons.
Final Thought:
By following these best practices, Java developers, system engineers, and DevOps professionals can ensure stable, efficient, and easily maintainable Java installations.