How to Install Java 11 & 12 on CentOS 7? Java is a very well-liked programming language that is used to create both desktop and lightweight mobile applications.
This detailed tutorial will demonstrate how to set up Java on CentOS 7.
- A user account with sudo privileges
- Access to the command line/terminal window
- The yum package manager, included by default
Versions of Java
There are now four Java platforms accessible:
- Standard Edition of Java (Java SE)
- Micro Editions of Java (Java ME)
- Enterprise Edition of Java (Java EE)
- JavaFX
How to Install Java 11 & 12 on CentOS 7? In this paper, we examine various Java SE packages.
Java Development Kit (Open JDK) and Java Runtime Environment are both free and open-source Java software programs (Open JRE). JDK is used for Java development and programming, whereas JRE is used to run Java-based applications.
Another SE implementation that is available and includes additional commercial capabilities is Java Oracle. The official Oracle JDK can be found on the company’s website or in a third-party repository. But keep in mind that the program can only be used for non-commercial purposes under its license.
CentOS Java Installation
On your computer, you can install one or more Java packages. By installing a certain version number, you can also choose whatever version you want on your system. Java 11 is the Long-Term Support (LTS) version that is currently the default.
1: Activate Openjdk 11
1: Update the package repository to ensure you download the newest software:
yum update sudo
2: After that, run the Java Development Kit installation command as follows:
Install Java 11-OpenJDK-Devel with sudo yum
The downloaded and installed JDK is shown in the output, as seen in the illustration below:
2: Activate OpenJRE 11
A subset of OpenJDK is the Java Runtime Environment 11 (Open JRE 11). Consequently, the command includes both packages:
Install Java 11-OpenJDK with sudo yum
3: Oracle Java 11 installation
1: Downloading the official Oracle JDK from the local repository is not possible. The.rpm package must be downloaded from the Java SE Downloads page.
2: Java SE 12 is the most recent version. Oracle Java 11 is the most recent stable version, and it is LTS.
On the website, find Java SE 11.0.3 (LTS) and click DOWNLOAD.
3: Use the following command to install the package after the download is finished:
- use the command sudo yum local install jre-VERSION-linux-x64.rpm
Make sure Java is set up on your computer
The command below displays your current Java release and verifies that the installation was successful:
version of Java
If Java was downloaded and installed properly, the output information should resemble the illustration below:
Install a specific Java version
By altering the command’s version number, you can also install any other version of Java.
1: Setup JDK 8
Instead of the usual OpenJDK 11, you might choose to use Open JDK 8.
Enter the following command on the terminal to accomplish this:
Install Java 1.8.0-openjdk-devel with sudo yum
2: Setup JRE 8
You can install Open JRE 8 as a part of Open JDK 8 by entering the command:
Install Java 1.8.0-openjdk with sudo yum
3: Oracle Java 12 installation
You must download Oracle Java from its official page, as was already explained.
Simply download the necessary package from their website, then continue with the installation to install the most recent version.
Establishing the Default Java Version
You can choose which version of Java is the default one since various versions of Java can be installed on your machine. To do that;
Run the following command to view every installed version on your computer:
alternatives to sudo —config java
Two alternatives to this approach are depicted in the graphic above. The Java 11 number 1, and the number 2, stand in for these options (Java 8).
Enter the corresponding number (in this case, 1 or 2) to alter the default version.
How to Set the Environment Variable JAVA HOME?
Other applications built using this programming language can access Java’s installation location with ease by setting the JAVA HOME environment variable.
1: Find the location of the Java installation:
update-alternatives sudo java configuration
You can find the path to each Java package that is installed on the system in the output.
/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7 6.x86 64/bin/java (where OpenJDK 11 is located)
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7 6.x86 64/jre/bin/java (where OpenJDK 8 is located) (where OpenJDK 8 is located)
2: Once you have seen every path, copy the one that corresponds to your desired Java version.
3: Next, open any text editor and navigate to the. Bash profile. Here’s an illustration using vim:
.bash profile for vim
4: Include a line at the bottom of the file that describes the location of JAVA HOME as follows:
JAVA HOME=”/your/installation/path/”
For instance, if we copied the Java 11 installation path in the previous step, the text editor will now include the following line:
/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7 6.x86 64/bin/java
How to Remove Java from CentOS?
Use the yum delete command if you need to uninstall any of the installed Java packages.
For instance, use the following command to get rid of Open JDK 8:
Remove Java with sudo yum
-1.8.0-openjdk-devel
It will uninstall the package from CentOS if you press “y” to confirm the procedure, as shown in the screenshot below:
/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7 6.x86 64/bin/java
Conclusion
You have learned How to Install Java 11 & 12 on CentOS 7 through this tutorial.
We also spoke about configuring the home environment variable and modifying the default version. You are now prepared to begin using Java!