1.1 System environment:
[Email protected] tools]# cat/etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
[Email protected] tools]# uname-r
3.10.0-123.el7.x86_64
[Email protected] tools]# uname-n
Nginx-daili
[Email protected] tools]# uname-m
x86_64
1.2 Download the JDK software and verify the package
Download the build installation package
wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.tar.gz
Check Package
[Email protected] tools]# md5sumjdk-8u73-linux-x64.tar.gz
1b0120970aa8bc182606a16bf848a686 jdk-8u73-linux-x64.tar.gz
[Email protected] tools]# CATJDK-8U73-LINUX-X64.MD5
Jdk-8u73-linux-x64.tar.gz md5:1b0120970aa8bc182606a16bf848a686
[Email protected] tools]#
1.3 Unzip the JDK program
[Email protected] tools]# tar zxf jdk-8u73-linux-x64.tar.gz
[Email protected] tools]# MV jdk1.8.0_73/usr/lib/
1.4 Create a soft link to the JDK directory to facilitate later JDK upgrades
Idea, create a soft link for the JDK program directory as a JDK or JVM, here for/USR/LIB/JDK soft links (the Yum installed JDK environment defaults to/USR/LIB/JVM), and then create a soft link to the Java and Javac in the program to/usr/ bin/, change the default name.
[Email protected] tools]# ln-s/USR/LIB/JDK1.8.0_73/USR/LIB/JDK
[Email protected] tools]# Mv/usr/bin/java/usr/bin/java.bak
[Email protected] tools]# ln-s/usr/lib/jdk/jre/bin/java/usr/bin/java
[Email protected] tools]# ln-s/usr/lib/jdk/bin/javac/usr/bin/javac
[Email protected] tools]# ll/usr/bin/java*
lrwxrwxrwx. 1 root root 3 months 09:23/usr/bin/java->/usr/local/jdk/jre/bin/java
lrwxrwxrwx. 1 root root 3 months 08:00/usr/bin/java.bak->/etc/alternatives/java
lrwxrwxrwx. 1 root root 3 months 09:23/usr/bin/javac->/usr/local/jdk/bin/java
Create Java and javac soft links for easy software upgrades
[Email protected] tools]# ll/usr/lib/java*
lrwxrwxrwx. 1 root root 3 months 09:13/usr/local/java->/usr/local/jdk1.8.0_73/jre/bin/java
lrwxrwxrwx. 1 root root 3 months 09:13/usr/local/javac->/usr/local/jdk1.8.0_73/bin/javac
1.5 Setting Java Environment variables
Cp-p/etc/profile/etc/profile.bak$ (date+%f)
[Email protected] usr]# tail-5/etc/profile
# #set Environment
Export JAVA_HOME=/USR/LIB/JDK
Export JRE_HOME=${JAVA_HOME}/JRE
Export Classpath=.:${java_home}/lib:${jre_home}/lib
Export Path=${java_home}/bin: $PATH
1.6 Set default JDK (optional action)
because there may be a default other version in the system JDK, so we 'll do the following to set up our installed JDK as the default JDK version.
Update-alternatives--install/usr/bin/javajava/usr/lib/jvm/java7/bin/java 300
Update-alternatives--install/usr/bin/javac Javac/usr/lib/jvm/java7/bin/javac 300
Update-alternatives--install/usr/bin/jarjar/usr/lib/jvm/java7/bin/jar 300
Update-alternatives--install/usr/bin/javah Javah/usr/lib/jvm/java7/bin/javah 300
Update-alternatives--INSTALL/USR/BIN/JAVAP JAVAP/USR/LIB/JVM/JAVA7/BIN/JAVAP 300
execute the following command, set the default version, after which the system will list the various existing JDK version, you will be prompted to select
# update-alternatives--config Java
1.7 Test success
[email protected] usr]# which Java
/usr/lib/jdk/bin/java
[email protected] usr]# which Javac
/usr/lib/jdk/bin/javac
[Email protected] usr]# java-version
Java Version "1.8.0_73"
Java (TM) SE Runtime Environment (BUILD1.8.0_73-B02)
Java HotSpot (TM) 64-bit Server VM (build25.73-b02, Mixed mode)
This article is from the "Lights Dim" blog, please be sure to keep this source http://freedyong.blog.51cto.com/2948158/1750191
CentOS 7 JDK Environment deployment