How to Install Java on CentOS / Fedora Linux

by Ismail.EL
0 comment

1- What is Java Platform?

Java platform is a collection of programs that help to develop and run programs written in the Java programming language. Java platform includes an execution engine, a compiler, and a set of libraries. JAVA is platform-independent language. It is not specific to any processor or operating system.

The installation of the following versions of Java are covered:

  • OpenJDK 8
  • OpenJDK 7
  • OpenJDK 6
  • Oracle Java 9
  • Oracle Java 8

2- Prerequisites

For this tutorial, you will require:

SystemRHEL 8 / CentOS 8
SoftwareJava
OtherPrivileged access to your Linux system as root or via the sudo command.

3. How to Install OpenJDK 8

This section will show you how to install the prebuilt OpenJDK 8 JRE and JDK packages using the yum package manager, which is similar to apt-get for Ubuntu/Debian. OpenJDK 8 is the latest version of OpenJDK

a. Install OpenJDK 8 JRE

To install OpenJDK 8 JRE using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

b. Install OpenJDK 8 JDK

To install OpenJDK 8 JDK using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

4. Install OpenJDK 7

This section will show you how to install the prebuilt OpenJDK 7 JRE and JDK packages using the yum package manager.

a. Install OpenJDK 7 JRE

To install OpenJDK 7 JRE using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

b. Install OpenJDK 7 JDK

To install OpenJDK 7 JDK using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

5. Install OpenJDK 6

This section will show you how to install the prebuilt OpenJDK 6 JRE and JDK packages using the yum package manager.

a. Install OpenJDK 6

To install OpenJDK 6 JRE using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

b. Install OpenJDK 6 JDK

To install OpenJDK 6 JDK using yum, run this command:

At the confirmation prompt, enter y then RETURN to continue with the installation.

6. Install Oracle Java 9

This section of the guide will show you how to install Oracle Java 9 JRE and JDK (64-bit), the latest release of these packages at the time of this writing.

We will be using the wget command to download the Oracle Java software packages, so install wget if it is not already installed by running:

a. Install Oracle Java 9 JRE

Change to your home directory and download the Oracle Java 9 JRE RPM with these commands:

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

At the confirmation prompt, enter y then RETURN to continue with the installation.

Now Java should be installed at /usr/java/jre-9.0.4/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

b. Install Oracle Java 9 JDK

Change to your home directory and download the Oracle Java 9 JDK RPM with these commands:

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

At the confirmation prompt, enter y then RETURN to continue with the installation.

Now Java should be installed at /usr/java/jdk-9.0.4/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

7. Install Oracle Java 8

This section of the guide will show you how to install Oracle Java 8 JRE and JDK (64-bit).

Note: You must accept the Oracle Binary Code License Agreement for Java SE, which is one of the included steps, before installing Oracle Java.

a. Install Oracle Java 8 JRE

Note: In order to install Oracle Java 8 JRE, you will need to go to the Oracle Java 8 JRE Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm package. Substitute the copied download link in place of the highlighted part of the wget command.

Change to your home directory and download the Oracle Java 8 JRE RPM with these commands:

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

At the confirmation prompt, enter y then RETURN to continue with the installation.

Now Java should be installed at /usr/java/jre1.8.0_161/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

b. Install Oracle Java 8 JDK

Note: In order to install Oracle Java 8 JDK, you will need to go to the Oracle Java 8 JDK Downloads Page, accept the license agreement, and copy the download link of the appropriate Linux .rpm package. Substitute the copied download link in place of the highlighted part of the wget command.

Change to your home directory and download the Oracle Java 8 JDK RPM with these commands:

Then install the RPM with this yum command (if you downloaded a different release, substitute the filename here):

At the confirmation prompt, enter y then RETURN to continue with the installation.

Now Java should be installed at /usr/java/jdk1.8.0_161/jre/bin/java, and linked from /usr/bin/java.

You may delete the archive file that you downloaded earlier:

8. Set Default Java

If you installed multiple versions of Java, you may want to set one as your default. Additionally, some applications require certain environment variables to be set to locate which installation of Java to use. This section will show you how to do this.

By the way, to check the version of your default Java, run this command:

Using Environment Variables

Many Java applications use the JAVA_HOME or JRE_HOME environment variables to determine which java executable to use.

For example, if you installed Java to /usr/java/jdk1.8.0_161/jre/bin (i.e. java executable is located at /usr/java/jdk1.8.0_161/jre/bin/java), you could set your JAVA_HOME environment variable in a bash shell or script like so:

If you want JAVA_HOME to be set for every user on the system by default, add the previous line to the /etc/environment file. An easy way to append it to the file is to run this command:

9. Conclusion

In this post, i have explained How To Install and Secure phpMyAdmin on Ubuntu.
If you have any questions or feedback, feel free to leave a comment.
As always, if you found this post useful, then click like and share it 🙂

20790cookie-checkHow to Install Java on CentOS / Fedora Linux

Related Posts

Leave a Comment