CentOS 安装 JDK

命令安装:

#    1、去官网下载jdk tar.gz文件

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"  http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz

#    2、解压下载的jdk文件到 '/usr/local/src' 目录下

tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/src/

#    3、为解压后的目录创建软链接

ln -s /usr/local/src/jdk1.8.0_91 /usr/local/jdk

#    4、配置环境变量

sed -i '$a JAVA_HOME=/usr/local/jdk\nCLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar\nPATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\n\nexport JAVA_HOME\nexport PATH\nexport CLASSPATH' /etc/profile
source /etc/profile

#    5、检测jdk是否安装成功

java -version && echo 'JDK 安装成功 '|| echo 'JDK 安装失败 '

 

脚本安装:

 1 #!/bin/bash
 2 wget \
 3     --no-check-certificate \
 4     --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
 5      http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz
 6 
 7 tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/src/
 8 
 9 ln -s /usr/local/src/jdk1.8.0_91 /usr/local/jdk
10 
11 sed -i '$a \
12 JAVA_HOME=/usr/local/jdk \
13 CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar \
14 PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH \
15 export JAVA_HOME \
16 export PATH \
17 export CLASSPATH' /etc/profile
18 
19 source /etc/profile
20 
21 java -version && echo 'JDK 安装成功 '|| echo 'JDK 安装失败 '

 

posted @ 2016-04-28 13:48  三角形  阅读(349)  评论(0编辑  收藏  举报