This is the installation procedure for OpenJDK8.
$ sudo yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
$ 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
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.
/etc/environment --A file that sets the default environment variables. It is common to edit this file if you want to change system-wide environment variables.
/etc/profile --A shell script file that runs at login. It is automatically loaded when the shell registered as the login shell is started.
~/.bash_profile --Specific user settings. .bash_profile runs only at login.
~/.bashrc --Specific user settings. It runs every time you start bash.
Quote source -Environment variable settings -Really correct use of .bashrc and .bash_profile
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
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);
}
}
$ javac day.java
Success if the current date and time is displayed
$ java day
2017/10/12 4:27
Recommended Posts