How to install Java on CentOS 8

Java is one of the most popular programming languages, and it can be used to build different types of applications and systems.

There are two different implementations of Java, OpenJDK and Oracle Java. Most of them are the same, except that Oracle Java has some additional commercial features. Oracle Java License only allows non-commercial use, such as personal use or developer use. OpenJDK is an open source implementation of the Java platform.

The default software source repository of CentOS 8 contains two long-term support versions of Java, Java 8 and Java 11.

In this guide, we will explain how to install one or more Java (OpenJDK) versions on CentOS 8 and how to set the default Java version.

One, install OpenJDK 11

It is usually recommended to install the latest Java long-term support version (JDK 11). Some Java-based applications may require a specific version of Java, so you may need to read the application documentation.

To install OpenJDK 11 on CentOS 8, run the following command as root or another user with sudo privileges:

sudo yum install java-11-openjdk-devel

Once the installation is complete, you can verify by checking the Java version number.

java -version

The output should look like this:

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)

that's it! You have successfully installed Java on CentOS 8 system.

CentOS 8 also supports OpenJDK minimum Java runtime environment, which can execute applications without GUI interface (no keyboard, no mouse, and no display system support). This version is suitable for server applications because it has fewer dependencies and uses fewer server system resources.

To install the OpenJDK 11 headless version, enter:

sudo yum install java-11-openjdk-headless

If you have installed java-11-openjdk-devel, the headless package will be installed as a dependent package.

Two, install OpenJDK 8

Java 8, the previous version of Java LTS, is still supported and widely used. If your application requires Java 8, you should enter the following command to install it:

sudo yum install java-1.8.0-openjdk-devel

Verify it by checking the Java version:

java -version

The output should look like this:

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)

To install the minimal java runtime environment, please install the java-1.8.0-openjdk-headless package.

Three, set the default Java version##

If you have installed multiple Java versions on your CentOS system, you can use alternatives to set the default Java version.

To check what the default Java version is, type:

java -version

If you want to change the default version, use the alternatives command:

sudo alternatives --config java

The output should look like this:

There are 2 programs which provide 'java'.

 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:

All installed Java versions are printed out on the screen. Enter the number you want to set as the default version, and press Enter.

You may want to change the default javac version:

sudo alternatives --config java

javac is a command tool used to compile Java programs.

Fourth, set **JAVA_HOME**environment variables##

The JAVA_HOME environment variable is used in some Java applications. It is used to indicate the location of the Java installation and to specify the Java version used.

To set the JAVA_HOME environment variable for each user, add it to the ~/.bashrc file, or any other configuration file that will be loaded when the user logs in. For system-level settings, use a script in the /etc/profile.d directory:

If you want to set JAVA_HOME to OpenJDK 8, add the following line to the bottom of the file: /etc/profile.d/java.sh

JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk"

If you want this modification to work in your current session, you can log out of the system and log in again, or use the following source command:

source /etc/profile.d/java.sh

Verify that the JAVA_HOME environment variable is set correctly:

echo $JAVA_HOME

The output shows the path to the Java installation:

/usr/lib/jvm/java-1.8.0-openjdk

You can also set JAVA_HOME in the application configuration file, in the systemd unit file, or on the command line when starting the program.

For example, if you want Mavan to use Java 8, you can enter:

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk mvn --version

Output:

...
Java version:1.8.0_222, vendor: Oracle Corporation, runtime:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el8_0.x86_64/jre
...

Five, summary##

CentOS 8 supports two main Java versions, Java 8 and Java 11, both of which can be installed using the yum package management tool.

Recommended Posts

How to install Java on CentOS 8
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to install TeamViewer on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
Install Java on Centos 7
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to install and configure Elasticsearch on CentOS 7
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to install Java on Ubuntu 16.04 using Apt-Get
How to install and configure VNC on CentOS 8
How to install and use Composer on CentOS 8
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
How to install and use Curl on CentOS 8
How to install and configure Owncloud on CentOS 8
How to install VirtualBox client extension on CentOS 8
How to install Oracle Java 14 on Ubuntu Linux
How to install Docker CE on RHEL 8 / CentOS 8
How to install and uninstall tomcat on centos