How to Install Java on Oracle Linux
Installing Java on Oracle Linux is a common task if you want to run Java applications or develop software on this platform. Whether you need the Java Development Kit (JDK) or just the Java Runtime Environment (JRE), getting Java set up correctly is essential for smooth operation. In this guide, I’ll walk you through the process step-by-step, making it easy for you to install Java on your Oracle Linux system.
You might be wondering which Java version to install or how to configure it properly. Don’t worry — I’ll cover everything from choosing the right Java package to verifying your installation. By the end, you’ll have Java ready to use on Oracle Linux, whether for development, running applications, or server tasks.
Understanding Java Versions and Oracle Linux Compatibility
Before installing Java, it’s important to know which version suits your needs and works well with Oracle Linux. Oracle Linux supports multiple Java versions, including OpenJDK and Oracle’s official JDK. Here’s what you should consider:
- OpenJDK: This is the open-source version of Java and is fully compatible with Oracle Linux. It’s free and widely used.
- Oracle JDK: Oracle’s official Java Development Kit, often used in enterprise environments. It may require a license for commercial use.
- Java 8, 11, 17, and later: These are the most common long-term support (LTS) versions. Java 17 is the latest LTS release, recommended for new projects.
Oracle Linux 8 and 9 support both OpenJDK and Oracle JDK. For most users, OpenJDK is sufficient and easier to install using the system’s package manager.
Preparing Your Oracle Linux System
Before installing Java, make sure your system is updated and ready. This helps avoid conflicts and ensures you get the latest security patches.
Update your system packages
Open a terminal and run:sudo dnf update -yInstall required tools
You might needwgetorcurlto download Java packages if you choose manual installation:sudo dnf install wget curl -yCheck your current Java version
If Java is already installed, check the version:java -version
If no Java is installed, you’ll see an error or no output.
Installing OpenJDK on Oracle Linux Using DNF
The easiest way to install Java on Oracle Linux is by using the DNF package manager. This method installs OpenJDK, which is fully compatible and free.
Steps to install OpenJDK
Search available OpenJDK packages
Run:sudo dnf search openjdkThis lists available Java versions like
java-1.8.0-openjdk,java-11-openjdk, andjava-17-openjdk.Install your preferred Java version
For example, to install OpenJDK 17:sudo dnf install java-17-openjdk-devel -yThe
-develpackage includes the JDK (development tools). If you only need the runtime, installjava-17-openjdkinstead.Verify the installation
Check the installed Java version:java -versionYou should see output confirming the installed OpenJDK version.
Setting the default Java version
If you have multiple Java versions installed, you can select the default using the alternatives system:
sudo alternatives --config java
This command lists installed Java versions. Enter the number corresponding to the version you want to use by default.
Installing Oracle JDK Manually on Oracle Linux
Sometimes, you might prefer Oracle’s official JDK, especially for enterprise use. Oracle JDK requires manual installation since it’s not available in the default repositories.
Steps to install Oracle JDK
Download Oracle JDK
Visit Oracle’s official Java download page and get the RPM package for Linux. You can also usewgetto download it directly:wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpmInstall the RPM package
Use thednfcommand to install the downloaded RPM:sudo dnf localinstall jdk-17_linux-x64_bin.rpmSet Oracle JDK as default
Use thealternativestool to configure the default Java:sudo alternatives --install /usr/bin/java java /usr/java/jdk-17/bin/java 2000 sudo alternatives --config javaVerify the installation
Run:java -versionIt should show Oracle JDK details.
Configuring Environment Variables for Java
After installing Java, setting environment variables like JAVA_HOME helps many applications find your Java installation.
How to set JAVA_HOME
Find the Java installation path
For OpenJDK, it’s usually under/usr/lib/jvm/. List the directory:ls /usr/lib/jvm/Edit your shell profile
Open your.bashrcor.bash_profilefile:nano ~/.bashrcAdd these lines at the end
Replace the path with your Java installation directory:export JAVA_HOME=/usr/lib/jvm/java-17-openjdk export PATH=$JAVA_HOME/bin:$PATHReload the profile
Run:source ~/.bashrcVerify JAVA_HOME
Check the variable:echo $JAVA_HOME
This setup ensures your system and applications know where Java is installed.
Troubleshooting Common Java Installation Issues
Sometimes, you might face problems during or after installing Java. Here are some common issues and how to fix them:
Java command not found
Make sure Java is installed and your PATH includes the Java binary directory. Usealternatives --config javato set the default.Multiple Java versions causing conflicts
Use thealternativestool to select the correct version.Permission denied during installation
Always usesudowhen installing packages or editing system files.JAVA_HOME not recognized
Confirm you added the correct path in your shell profile and reloaded it.
If problems persist, checking Oracle Linux forums or official documentation can help.
Using Java on Oracle Linux: Basic Commands and Tips
Once Java is installed, you can start using it for running applications or development.
Basic Java commands
Check Java version
java -versionCompile Java code
javac HelloWorld.javaRun Java program
java HelloWorld
Tips for managing Java on Oracle Linux
- Keep your Java updated using
dnf updatefor OpenJDK. - Use
alternativesto switch between Java versions easily. - Set
JAVA_HOMEglobally by editing/etc/profile.d/java.shfor system-wide access. - For server environments, consider installing Java as a service or using containerized Java applications.
Conclusion
Installing Java on Oracle Linux is straightforward once you know the right steps. Whether you choose OpenJDK via DNF or Oracle’s official JDK manually, you can have Java up and running quickly. Remember to update your system first, pick the Java version that fits your needs, and configure environment variables properly.
With Java installed, you’re ready to develop, run applications, or manage Java-based services on Oracle Linux. If you ever need to switch versions or troubleshoot, the alternatives tool and environment variable settings will be your best friends. Enjoy coding and running Java applications on your Oracle Linux system!
FAQs
How do I check if Java is already installed on Oracle Linux?
Open a terminal and type java -version. If Java is installed, it will show the version. Otherwise, you’ll get a command not found error.
Can I install multiple Java versions on Oracle Linux?
Yes, you can install multiple versions using DNF or manual RPM installs. Use the alternatives command to switch between them.
What is the difference between OpenJDK and Oracle JDK?
OpenJDK is the free, open-source version of Java, while Oracle JDK is Oracle’s official distribution, often used in enterprise settings and may require a license.
How do I set JAVA_HOME permanently on Oracle Linux?
Add the export JAVA_HOME=your_java_path line to your .bashrc or /etc/profile.d/java.sh file, then reload the profile with source ~/.bashrc.
Is OpenJDK suitable for production use on Oracle Linux?
Yes, OpenJDK is fully compatible and widely used in production environments on Oracle Linux and other Linux distributions.
