Install Java Open JDK 8 on CentOS 7

Overview

This is the installation procedure for OpenJDK8.

environment

Install OpenJDK8

$ sudo yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel 

Confirm path

$ dirname $(readlink $(readlink $(which java)))
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre/bin

Setting environment variables

Set the following as environment variables somewhere.

JAVA_HOME sets the part before / jre / bin of the above path confirmation.

$ sudo vi /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar 
$ source /etc/profile

The above example sets environment variables in / etc / profile, Please refer to the following when setting in other locations.

Set default JDK

Change the default if another version of the JDK is already installed. In the example below, only one is included.

$ sudo alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 1

Operation check

Create the following program to check the operation.

day.java


import java.util.Calendar;

class day {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DATE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute);
    }
}

compile

$ javac day.java

Run

Success if the current date and time is displayed

$ java day
2017/10/12 4:27

reference

-OpenJDK 8 installation

Recommended Posts

Install Java Open JDK 8 on CentOS 7
Install Java 9 on windows 10 and CentOS 7
Install Java on Mac
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Install Vertica 10.0 on CentOS 6.10
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install Python 3 on CentOS 7
Install kuromoji on CentOS7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Install OpenJDK7 (JAVA) on ubuntu 14.04
Install OpenFOAM v2006 on CentOS
Install Java on WSL Ubuntu 18.04
Install Jenkins on Docker's CentOS
Install Apache on CentOS on VirtualBox
Java version change on CentOS
Install Ruby 2.7 on CentOS 7 (SCL)
Install java 1.8.0 on Amazon linux2
Try DPDK20 SDK on CentOS7 â‘ Install
Install JDK and JRE on Ubuntu 16.10
Install Java with zip on Windows
Install Ruby 2.5 on CentOS 7 using SCL
How to install MariaDB 10.4 on CentOS 8
Install apache 2.4.46 from source on CentOS7
Steps to install MySQL 8 on CentOS 8
Steps to install devtoolset-6 on CentOS 7
Install Java development environment on Mac
If you can't install java on Catalina
Install samba4 from source code on CentOS8
Change JDK and Tomcat versions on CentOS
Install OpenJDK (Java) on the latest Ubuntu
[Java] Stepping on a JDK compiler bug
Install the webmail client Rainloop on CentOS 8
How to install beta php8.0 on CentOS8
Install Java8 with Yum on Amazon Linux
Install CentOS 7 on Raspberry pi 4 Model B
Install MariaDB (CentOS 8)
Java installation jdk
[CentOS] Install apache-loggen
OpenVPN on CentOS 8
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Command to install nginx / PHP7 / php-fpm on CentOS7
Install Java 11 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install Java 14 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install Java 8 (OpenJDK: AdoptOpenJDK) on macOS with Homebrew
Install GitLab on CentOS 8 with no internet connection
[Java] How to switch from open jdk to oracle jdk
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
Install CMS Made Simple v2.2.2 on LAMP on CentOS 7.3
Install java with Homebrew
Install gradle on mac
Let's touch on Java
Install Corretto 8 on Windows
Maven on CentOS 7 tutorial
Install OpenJDK on macOS