Oracle Linux

How to Install Java on Oracle Linux 8?

Two separate Java implementations exist, the OpenJDK and Oracle Java. Both implementations are essentially based on the same code, however, Oracle Java includes some proprietary code, while OpenJDK, the reference implementation of Java, is completely open source. Many Java programs would also run well, but you can use whatever the program needs to be implemented.

To install Java on Oracle Linux 8, you have to install the latest JDK from the official release website. The JDK stands for Java Development Kit, an application of any one of the Micro Version platforms of the Java Platform published by Oracle Corporation. To install it on your Oracle Linux 8, you have to follow this article very eagerly.

Prerequisites

  • Oracle Linux 8 installed on your Virtual Box
  • Must have root user privileges

Download RPM File

To install Java in your Oracle Linux 8 system, you have to first download the RPM file for Oracle Linux 8.

Open any installed browser and search for the Java SE Oracle Download website. Click on the JDK Download to proceed.

There are a lot of RPM packages available on the JDK download page. You have to pick the Linux x64 RPM Package. Under the Download label, click on the .rpm JDK file to download it.

You will then see the below dialogue box. Checkmark the License Agreement terms and click on the Download button, followed by the RPM file name, to continue the download.

Another dialogue window will be opened. Pick the Save File option, and hit the OK to continue the download.

You can see that the download has started. Wait for some time until the download has been completed.

The downloaded JDK RPM file is now residing in the Downloads folder as cited below.

Check Repositories and Java Version

Firstly, open your Oracle Linux 8 terminal and add the following command to check installed repositories:

$ sudo yum repolist

To check whether your Oracle system has any JDK package installed, use the following command:

$ sudo yum list jdk*

You can also verify the latest version of the default Java version compatible and enabled for your system, using the command as follows:

$ java -version

Check Default Java Path

You can use the command below to check the default Java path of JDK:

$ which java

You can see the default JDK path is /usr/bin/java.

To check the link file, which is /etc/alternatives/java, you can use the appended command below:

$ls –ltr /usr/bin/java

Unlink the Default Path

To unlink this file, e.g., /etc/alternatives/java, you have to login as a root user, as cited below:

$ su

Note: It will ask for your root password.

# unlink /etc/alternatives/java
# exit

So, upon checking the version of Java, you will find that there is no such file or directory.

You can also check the file using the following “which” command:

$ which java

Now, the Open JDK has been disabled completely.

Install JDK

To install JDK in Oracle Linux 8, open your Downloads folder, where you have downloaded the JDK file. Press the Right-key button from the mouse and hit on Open in Terminal. You will then see that your terminal has been opened. Login as a root user using the following command:

$ su

Using the list command, you can list the RPM file as follows:

$ ls

Finally, you can install the JDK file. You have to use the rpm command, followed by the name of a file, as cited below:

$ rpm –ivh jdk-15.0.1_linux-x64_bin.rpm

Wait for some time until the JDK file has been installed. You will see that it will fail to read the link /usr/bin/java because we have already unlinked it.

Check RPM Package Name

To check the RPM file package name that has just been installed, execute the following command on your oracle Linux 8 terminal:

$ rpm –qa |grep jdk-15

Check Directories and Files in Java

To check the directories and files used by JDK 15, you have to use the following rpm command, followed by the package name brought in the upper command:

$ rpm –ql jdk-15.0.1-15.0.1-ga.x86_64

You will see a long list of directories and folders used by the JDK package.

When you check the version of Java, it will show you the latest version that has just been installed, as appended below:

$ java -version

You can also check the version of Java only, as cited below:

$ javac –version

Launch Java

To verify whether you installed the JDK kit and if it is working properly, you can use the affixed command:

$ java

Another command to check the working of Java is as follows:

$ javac

When you check the Java link path, where the Java resides, it will show you the same old path. This means that /usr/bin/java has been replaced by the new JDK 15, as cited below:

$ which java

Check File Path

Now to check the link file details, you have to use the list command, followed by /usr/bin/java path, as cited below:

$ ls –ltr /usr/bin/java

Link File Path

At last, you can link this newly created Java with the old file path. You can also do that by using the following command:

$ ls –la /etc/alternatives/

Conclusion

We have discussed how to switch to root user in Linux Oracle 8, download RPM JDK file, remove link for default file path, check repositories and version, install JDK Kit on Oracle Linux 8, and link the default file path. Hopefully, you are now able to do all these particular tasks by following this guide.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.