Atlantic.Net Blog

How to Install Java on CentOS 8

Hitesh Jethva
by Atlantic.Net (85posts) under VPS Hosting
0 Comments

Java JDK is a free and open-source software development kit used for building applications, applets, and components using the Java programming language. Java JDK comes with a set of tools for developing and testing applications written in the Java programming language; these tools include JRE, Java, Javac (Compiler) and Jar (Archiver).

There are two different implementations of Java, OpenJDK and Oracle JDK:

  • OpenJDK is the free and open-source implementation of the Java Platform.
  • Oracle JDK is a paid and permits only non-commercial use of the software.

In this tutorial, we will show you how to install OpenJDK 8, OpenJDK 11 and Oracle Java JDK 14 on CentOS 8.

Prerequisites

  • A fresh CentOS 8 VPS on the Atlantic.Net Cloud Platform.
  • A root password configured on your server.

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server.  Create a new server, choosing CentOS 8 as the operating system with at least 1GB 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 into your CentOS 8 server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install OpenJDK 11

By default, OpenJDK 11 is available in the CentOS 8 default repository. You can install it by running the following command:

dnf install java-11-openjdk -y

Once installed, verify the installed Java version with the following command:

java -version

You should see the following output:

Step 3 – Install OpenJDK 8

By default, OpenJDK 8 is available in the CentOS 8 default repository. You can install it with the following command:

dnf install java-1.8.0-openjdk -y

Once installed, verify the installed Java version with the following command:

java -version

You should see the following output:

Step 4 – Set Up the Default Java Version

At this point, you have two different versions of Java installed on your system. You can switch between multiple Java versions using the following command:

alternatives --config java

In the following output, you should see that OpenJDK 8 is the default version on your system.

Type 1 and press Enter to switch the Java version from OpenJDK 8 to OpenJDK 11.

Now, verify the default Java version with the following command:

java -version

You should see that OpenJDK 11 is the default Java version on your system.

Step 5 – Setup JAVA_HOME Environment Variable

In some Java-based applications, you will need to define the installation location of Java to specify which Java version you want to use to run the application. You can use the JAVA_HOME environment variable to define the Java installation path.

You can set the JAVA_HOME environment variable for OpenJDK 11 by editing the file /etc/profile:

nano /etc/profile

Add the following line at the end of the file:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-11.0.5.10-2.el8_1.x86_64/"

Save and close the file when you are finished. Then, activate the changes with the following command:

source /etc/profile

Next, verify the JAVA_HOME environment with the following command:

echo $JAVA_HOME

You should get the following output:

Step 6 –  Install Oracle Java 14

First, you will need to download the Oracle Java 14 RPM package file from the Oracle download page, as shown below.

Here, you can see the different versions of Java 14. Click on jdk-14_linux-x64_bin.rpm  to download it in your system.

You may now need to upload the file to your Centos8 server from your local desktop. This can be done using WinSCP.

Download WinSCP and install WinSCP using the following guide:

https://winscp.net/eng/docs/guide_install

Upload the file using your CentOS 8 server information:

Once the upload has completed, you can install it with the following command:

dnf localinstall jdk-14_linux-x64_bin.rpm -y

Once installed successfully, change the default Java version to Oracle Java 8 with the following command:

alternatives --config java

You should see a list of different Java versions in the following output:

Type 3 and hit Enter to change the default Java version.

Next, verify the Java default version with the following command:

java -version

You should see the following output:

Conclusion

Congratulations! You have successfully installed Java on CentOS 8. I hope you have now enough knowledge to switch between different Java versions and start building your application on your virtual private server.

Get A Free To Use Cloud VPS

Free Tier Includes:
G2.1GB 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

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G2.1GB 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

2323 Bryan Street,

Dallas, Texas 75201

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