一键更换
function just_do_it(){
echo '系统自带openjdk版本是:'java -version
echo '1.开始卸载openjdk'
yum remove "*openjdk*" -y
echo '卸载系统自带openjdk成功'
echo '2.创建sunjdk文件夹所在位置'
mkdir -p /usr/local/java && cd /usr/local/java
echo '创建sunjdk文件夹成功'
echo '4.下载文件'
#wget https://download.oracle.com/otn/java/jdk/8u261-b12/a4634525489241b9a9e1aa73d9e118e6/jdk-8u261-linux-x64.tar.gz?AuthParam=1599464260_6014d8d3083aaa13876765204ca4043d
# 下载不到jdk的话去百度云盘,链接在此
#链接: https://pan.baidu.com/s/1-3pl106l0IxPvql-VXJjZw 提取码: ugnh
#mv /usr/local/src/jdk-8u261-linux-x64.tar.gz .
echo '解压'
tar -zxvf jdk-8u261-linux-x64.tar.gz
echo '5.添加配置文件'
echo
'export JAVA_HOME=/usr/local/java/jdk1.8.0_261
export JRE_HOME=/usr/local/java/jdk1.8.0_261/jre
export CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH'
>> ~/.bash_profile
sleep 5
echo '6.建立软连接'
ln -s /usr/bin/java /usr/local/java/
echo 'sunjdk版本号为:'
java -version
echo 'jdk版本升级完成'
}
# 入口
just_do_it
source ~/.bash_profile
rm -rf /usr/bin/java && ln -s /usr/local/java/jdk1.8.0_261/bin/java /usr/bin/java