每次都要卸载系统跟随的openjdk然后装orcle的jdk实在烦人,所以

编写一个脚本执行就省心了,只要将下面的bash脚本和你所在下载的

jdk-7u79-linux-x64.tar.gz包放在同一个文件夹即可。

别忘记,给脚本执行权限


#chmod +x shellname.sh

#../shellname.sh





#!/bin/bash

#shell script to install jdk 



# 1. remove openjdk if exists.


for i in $(rpm -qa | grep openjdk | grep -v grep)

do

 echo "Deleting rpm -> "$i

 rpm -e --nodeps $i

done


if [[ ! -z $(rpm -qa | grep jdk | grep -v grep) ]];

then

 echo "-->Failed to remove the defult Jdk."

else



# 2.tar and install JDK(jdk-7u79-linux-x64.tar.gz)


 tar -zxvf jdk-7u79-linux-x64.tar.gz

 mkdir /usr/java

 mv ./jdk1.7.0_79 /usr/java/jdk1.7.0_79

 rm -rf ./jdk1.7.0_79



# 3. config /etc/profile


 echo "export JAVA_HOME=/usr/java/jdk1.7.0_79" >>/etc/profile

 echo -e 'export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar'>>/etc/profile

 echo -e 'export PATH=$PATH:$JAVA_HOME/bin'>>/etc/profile


 source /etc/profile


fi