Learn how to install Java on Rocky Linux 9 with our comprehensive step-by-step guide. Set up the Java Development Kit (JDK) and Runtime Environment (JRE) to start developing and running Java applications on your Linux system. #centlinux #linux #java
Table of Contents
What is Java?
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need to recompile. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture.
The syntax of Java is similar to C and C++, but has fewer low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as reflection and runtime code modification) that are typically not available in traditional compiled languages. As of 2019, Java was one of the most popular programming languages in use according to GitHub, particularly for client–server web applications, with a reported 9 million developers. (Source: Wikipedia)
Java was originally developed by James Gosling at Sun Microsystems. It was released in May 1995 as a core component of Sun Microsystems’ Java platform. The original and reference implementation Java compilers, virtual machines, and class libraries were originally released by Sun under proprietary licenses. As of May 2007, in compliance with the specifications of the Java Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference implementation is the OpenJDK JVM which is free open-source software and used by most developers and is the default JVM for almost all Linux distributions.
As of September 2022, Java 19 is the latest version, while Java 17, 11 and 8 are the current long-term support (LTS) versions.
Java vs Python
Java and Python are two of the most popular programming languages, each with its strengths and ideal use cases. Here’s a comparison of Java and Python across various dimensions:
Java
Pros
- Performance: Generally faster execution due to its statically-typed nature and Just-In-Time (JIT) compiler.
- Robustness: Strong type-checking at compile-time helps catch errors early.
- Scalability: Well-suited for large, complex, and high-performance applications, especially in enterprise environments.
- Platform Independence: Write Once, Run Anywhere (WORA) with the Java Virtual Machine (JVM).
- Rich Ecosystem: Extensive libraries, frameworks (like Spring, Hibernate), and tools.
Cons
- Verbosity: More boilerplate code required, which can make development slower and code harder to read.
- Learning Curve: Steeper learning curve due to its strict syntax and object-oriented principles.
Best for
- Enterprise-level applications.
- Android app development.
- Large-scale web applications.
- Financial services.
Python
Pros
- Simplicity: Simple and readable syntax, making it easy to learn and write.
- Rapid Development: Ideal for quick prototyping and development.
- Versatility: Wide range of applications, from web development to data science, AI, and scripting.
- Rich Ecosystem: Extensive libraries and frameworks (like Django, Flask, TensorFlow, Pandas).
- Community Support: Strong community and vast amount of resources for learning and troubleshooting.
Cons
- Performance: Generally slower execution compared to Java, as it is interpreted and dynamically typed.
- Less Strict: Dynamically-typed nature can lead to runtime errors that are harder to debug.
Best for
- Web development.
- Data science and machine learning.
- Automation and scripting.
- Prototyping and smaller projects.
Feature Comparison
Feature | Java | Python |
---|---|---|
Typing | Statically-typed | Dynamically-typed |
Performance | High | Moderate |
Syntax | Verbose, strict | Concise, readable |
Learning Curve | Steeper | Gentle |
Development Speed | Moderate | Fast |
Popular Frameworks | Spring, Hibernate, Struts | Django, Flask, TensorFlow |
Use Cases | Enterprise apps, Android, large-scale systems | Web development, data science, automation |
Conclusion
- Choose Java if you need a language for developing large, performance-critical applications, particularly in enterprise settings or for Android development.
- Choose Python if you want a versatile, easy-to-learn language for rapid development, especially for web development, data science, machine learning, or automation tasks.
Both languages have their unique strengths and can often complement each other in a diverse technology stack.
Recommended Training: Java Masterclass 2025: 130+ Hours of Expert Lessons from Tim Buchalka
Environment Specification
For this guide, we are working with a minimal installation of Rocky Linux 9, running on a virtual machine specifically configured to suit the needs of this tutorial. This setup ensures a streamlined environment with only the essential components installed, minimizing unnecessary services and software. Below are the specifications of our Rocky Linux 9 virtual machine:
- CPU – 3.4 Ghz (2 cores)
- Memory – 2 GB
- Storage – 20 GB
- Operating System – Rocky Linux release 9.0 (Blue Onyx)
- Hostname – java-01.centlinux.com
- IP Address – 192.168.116.130/24
This minimal configuration provides a clean slate to demonstrate the steps without interference from pre-installed packages or services, making it easier to replicate and understand. Adjust these specifications as needed based on your project requirements.
Update Linux Operating System
By following the best practice, update your Linux operating system before installing Java 19 software.
Login as root user on your Linux server by using a ssh client.
Refresh your yum cache as follows.
# dnf makecache Rocky Linux 9 - BaseOS 786 B/s | 3.6 kB 00:04 Rocky Linux 9 - AppStream 1.6 kB/s | 3.6 kB 00:02 Rocky Linux 9 - Extras 334 B/s | 2.9 kB 00:08 Metadata cache created.
Update software packages in your Linux operating system.
# dnf update -y
If the above command update your Linux Kernel then, you should reboot your operating system with new Kernel before installing Java 19 software.
# reboot
Check the Linux operating system and Kernel versions as follows.
# cat /etc/rocky-release Rocky Linux release 9.0 (Blue Onyx) # uname -r 5.14.0-70.26.1.el9_0.x86_64
How to install Java on Rocky Linux 9
Java 19, the latest release of the Java programming language at the time of this writing, is readily available for download from Oracle’s official website. This version includes cutting-edge features and improvements designed to enhance performance, security, and developer productivity.
To obtain Java 19, navigate to the Oracle Java Downloads page. There, you can find the appropriate installer or archive tailored to your operating system and architecture, including options for Linux, Windows, and macOS. Oracle also provides detailed release notes, documentation, and support resources to guide you through the installation and setup process.
Downloading directly from Oracle ensures that you receive the official, up-to-date version of the software, free from modifications or potential security risks. Make sure to review Oracle’s licensing terms to confirm your use case aligns with their distribution policies. For enterprise environments or production servers, consider enabling updates and patches to keep your Java installation secure and efficient.
Copy the URL according to your preferred platform and then you can use wget command to download the Java 19 software directly from Linux commandline.
But first, use following command to install wget utility, if it isn’t already installed on your Linux machine.
# dnf install -y wget
Now, by using following commands, download Java 19 RPM into /tmp directory.
# cd /tmp # wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm --2022-10-26 11:34:05-- https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm Resolving download.oracle.com (download.oracle.com)... 104.91.72.85 Connecting to download.oracle.com (download.oracle.com)|104.91.72.85|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 169483428 (162M) [application/x-redhat-package-manager] Saving to: ‘jdk-19_linux-x64_bin.rpm’ jdk-19_linux-x64_bi 100%[===================>] 161.63M 956KB/s in 2m 20s 2022-10-26 11:36:27 (1.16 MB/s) - ‘jdk-19_linux-x64_bin.rpm’ saved [169483428/169483428]
After successful download, you can invoke dnf command to install Java 19 on Rocky Linux 9.
# dnf install -y jdk-19_linux-x64_bin.rpm Last metadata expiration check: 0:18:02 ago on Wed 26 Oct 2022 11:27:06 AM CDT. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Installing: jdk-19 x86_64 2000:19.0.1-10 @commandline 162 M Transaction Summary ================================================================================ Install 1 Package Total size: 162 M Installed size: 318 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : jdk-19-2000:19.0.1-10.x86_64 1/1 Running scriptlet: jdk-19-2000:19.0.1-10.x86_64 1/1 Verifying : jdk-19-2000:19.0.1-10.x86_64 1/1 Installed: jdk-19-2000:19.0.1-10.x86_64 Complete!
To verify Java 19 installation, execute java command to check the version of active Java software. (Note: You can run multiple versions of Java on a Single Linux operating system with the help of alternatives command.)
# java --version java 19.0.1 2022-10-18 Java(TM) SE Runtime Environment (build 19.0.1+10-21) Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)
Java 19 has been successfully installed on your Rocky Linux 9 system. To ensure seamless operation and compatibility for Java-based applications, it is recommended to set the necessary Java environment variables. These variables include JAVA_HOME
, which points to the Java installation directory, and PATH
, which allows Java commands to be executed from any location in the terminal. Configuring these environment variables ensures that your system correctly identifies the Java version and location, providing a consistent runtime environment for your applications.
# cat << EOF > /etc/profile.d/java.sh > export JAVA_HOME=/usr/lib/jvm/jdk-19-oracle-x64 > export PATH=$PATH:$JAVA_HOME/bin > EOF
Video Tutorial
If you prefer a step-by-step visual guide, we’ve also created a detailed video tutorial on “How to Install Java on Rocky Linux 9.” The video walks you through every step of the installation process, from updating your system to verifying your Java version. It’s perfect for users who like to follow along visually or need additional clarity on any of the steps mentioned in this guide. Be sure to check it out for a more interactive learning experience!
Final Thoughts
Congratulations on successfully learning how to install Java on Rocky Linux 9! With Java set up, you can now develop and run Java applications efficiently. Whether you’re working on development projects, running Java-based software, or learning Java programming, having a properly configured Java environment on your system will greatly enhance your productivity.
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!