• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Java on CentOS 8

Written by Admin, Updated On December 17, 2019
centos, java
How to Install Java on CentOS 8

Java is the popular programming language in the world. It is owned by Oracle and used to build different kinds of applications. This tutorial describes how to install various versions and implementations of Java on CentOS 8. We’ll show you how to install OpenJDK as well as Oracle Java. OpenJDK is an open-source implementation of the Java Platform while you can use Oracle Java only for non-commercial purpose, such as personal use and development use.

Default CentOS 8 repositories includes Java 8 and Java 11 Java LTS versions.

Installing OpenJDK 11#

It is always recommended to install the latest Java LTS (JDK 11) version. Run the following command to install the OpenJDK 11 on CentOS 8. Make sure that you are login as root or user with sudo privileges:

sudo yum install java-11-openjdk-devel

Now verify the installation by typing :

java -version

The output should display as given below:

openjdk version "11.0.4" 2019-07-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.4+11-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.4+11-LTS, mixed mode, sharing)

Alright! You have successfully installed Java on your CentOS 8 machine.

You also can install headless version of OpenJDK which have minimal Java runtime which used where not need of graphical user interface. This version is more convenience for server applications due to fewer dependencies and uses less system resources.

Execute below command to install headless OpenJDK 11:

sudo yum install java-11-openjdk-headless

Installing OpenJDK 8#

Java 8 is most widely used LTS version of Java and will be supported untill March 2025. Some of applications requires specific version of JDK. You can install Java 8 by typing below command:

sudo yum install java-1.8.0-openjdk-devel

Once the installation complete verify the installation by checking the Java version:

java -version

It will show output as below:

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Setting the Default Java Version#

If your system have multiple verions of Java on your CentOS system, you can set default Java version to use default when you type java in the terminal.

First of all, check current default version by typing:

java -version

Run the alternatives command to set up default version:

sudo alternatives --config java

It will show all the installed Java versions as below:

Selection    Command
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.4.11-0.el8_0.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el8_0.x86_64/jre/bin/java)
 Enter to keep the current selection[+], or type selection number: 

There are 2 programs which provide ‘java’. Select the number of the version you want to use as the default and hit Enter.

You can also change javac (compiling Java programs) version using below command:

sudo alternatives --config java

Conclusion#

CentOS 8 supports Java 8 and Java 11 LTS versions, you can install using yum package manager on your CentOS system.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install WordPress with Nginx on Debian 10
Next Article   How to Install Node.js and npm on Debian 10 Linux

Related Posts

  • How to Install Jenkins on Debian 11

    How to Install Jenkins on Debian 11

    January 5, 2023
  • How to Install Java on Ubuntu 22.04

    How to Install Java on Ubuntu 22.04

    December 25, 2022
  • How to Install Jenkins on Ubuntu 22.04

    How to Install Jenkins on Ubuntu 22.04

    December 23, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook