CentOS 7
Ads

JDK 8 : Install
2015/03/16
 
Install Java SE Development Kit 8 (JDK8) and build Java Environment.
[1] Download and install JDK 8.
Make sure the latest version and source URL of JDK on Oracle download site.
[root@dlp ~]#
curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u71-b15/jdk-8u71-linux-x64.rpm"
[root@dlp ~]#
rpm -Uvh jdk-8u71-linux-x64.rpm

Preparing...                ############################## [100%]
   1:jdk1.8.0_71            ############################## [100%]
Unpacking JAR files...
        rt.jar...
        jsse.jar...
        charsets.jar...
        tools.jar...
        localedata.jar...
        jfxrt.jar...

[root@dlp ~]#
vi /etc/profile
# add follows to the end

export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
[root@dlp ~]#
source /etc/profile
[2] If another version of JDK had been installed, change the default like follows.
[root@dlp ~]#
alternatives --config java


There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64/jre/bin/java
   2           /usr/java/jdk1.8.0_71/jre/bin/java

# select the latest one
Enter to keep the current selection[+], or type selection number: 2
[3] Create a test program and make sure if it works normally.
[root@dlp ~]#
vi 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

[root@dlp ~]#
javac day.java

# run

[root@dlp ~]#
java day

2015/3/16 20:30
 
Tweet