Atlantic.Net Blog

How to Install and Manage Java Versions on Oracle Linux 8

Hitesh Jethva
by Atlantic.Net (429 posts) under Dedicated Server Hosting, Tutorials
0 Comments

Java is an open-source, powerful, and widely used programming language. It is used to build web-based applications, games, chatbots, enterprise applications, and more. It is cross-platform and can be run on all operating systems.

You will require an IDE on your system to develop Java applications. The Java package is offered by OpenJDK or Oracle JDK. Java JDK is a free, open-source, and powerful software development environment used for developing Java Applications. JDK is a collection of programming tools including Javac, JRE, Jar, and Java.

In this post, we will show you how to install and manage different Java versions on Oracle Linux 8.

Prerequisites

  • A server running Oracle Linux 8 on the Atlantic.Net Cloud Platform
  • A root password configured on your server

Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Oracle Linux 8 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

dnf update -y

Install OpenJDK 18

At the time of writing this article, the latest version of Java OpenJDK is version 18. By default, the latest version is not available in the Oracle Linux 8 default repository, so you will need to install it from the source.

First, download the latest version of OpenJDK from the Java official website:

curl  -O https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvf openjdk-18_linux-x64_bin.tar.gz

Next, move the extracted directory to the /opt directory:

mv jdk-18 /opt/

Next, you will need to add the Java source path to the system environment. You can do it by creating the file java.sh:

nano /etc/profile.d/java.sh

Add the following lines:

export JAVA_HOME=/opt/jdk-18
export PATH=$PATH:$JAVA_HOME/bin

Save and close the file, then activate the Java path using the following command:

source /etc/profile.d/java.sh

Next, verify the Java path using the following command:

echo $JAVA_HOME

Sample output:

/opt/jdk-18

You can also verify the Java version using the following command:

java --version

You will get the following output:

openjdk 18 2022-03-22
OpenJDK Runtime Environment (build 18+36-2087)
OpenJDK 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)

Install OpenJDK 11 and OpenJDK 8

By default, OpenJDK 11 is available in the Oracle Linux default repository. You can install it using the following command:

dnf install java-11-openjdk-devel -y

You can also install the OpenJDK 8 from the Oracle Linux default repository using the following command:

dnf install java-1.8.0-openjdk-devel

Install Oracle JDK 18

At the time of writing this article, the latest version of Oracle JDK is 18. First, you will need to download it from its official website:

wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.rpm

Once the download is completed, you can install it using the following command:

rpm -ivh jdk-18_linux-x64_bin.rpm

You will get the following output:

warning: jdk-18_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-18-2000:18.0.1.1-ga          ################################# [100%]

Next, verify the Java version using the following command:

java --version

Manage Java Versions

Java also allows you to install and manage multiple Java versions in the same system. You can use the “alternatives –config java” command to easily switch between multiple Java versions:

alternatives --config java

You will be asked to set the default Java versions as shown below:

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.15.0.10-2.el8_6.x86_64/bin/java)
   2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.332.b09-2.el8_6.x86_64/jre/bin/java)
*+ 3           /usr/java/jdk-18.0.1.1/bin/java

Enter to keep the current selection[+], or type selection number: 1

Select your preferred option and hit Enter to set the default Java version.

Conclusion

In this post, we explained how to install OpenJDK 18, 11, 8, and Oracle JDK 18 on Oracle Linux 8. You also learned how to manage and switch between different Java versions. You can now start developing a Java application using your preferred Java version. Try it on dedicated hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Sails.js Framework with Nginx on Oracle Linux 8
How to Install OTRS on Oracle Linux 8
How to Install and Configure Caddy Web Server with PHP on Oracle Linux 8
How to Install and Use PIP Python Package Manager on Oracle Linux 8
How to Install FTP Server with ProFTPD on Oracle Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2008 Lookout Dr,

Dallas, Texas 75044

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources