本文最后更新于 1681 天前,其中的信息可能已经有所发展或是发生改变。
写作目的
方便重复使用的时候能方便点
因为Oracle下载JDK 8要登陆了,方便的PPA source 嗝屁了
成果
shell脚本
#!/bin/bash
temp_path="/root/temp_$RANDOM"
Jvm_lib="/usr/lib/jvm/"
temp_jdk_path=$temp_path"/jdk1.8.0_212"
jdk_path=$Jvm_lib"jdk1.8.0_212"
profile_path="/etc/profile.d/jdk-1.8.sh"
jdk_num=1
cd ~
if [ id -u = 0 ]
then
echo "Root Confirmed"
else
echo "Root or sudo required"
return 0
fi
echo "Remove openjdk*, Comfirm? (Y or y is comfirm)"
read is_comfirm
if [ "$is_comfirm"x == "Y"x ] || [ "$is_comfirm"x == "y"x ]
then
echo "ALL Openjdk will be remove!"
apt purge openjdk*
else
echo "How many jdks do you hava?"
read jdk_num
fi
echo "Make and entry temp path: "$temp_path
mkdir $temp_path
cd $temp_path
echo "Start Download JDK 8u212 x64"
wget --no-check-certificate https://dmca.makiras.org/jdk-8u212-linux-x64.tar.gz
echo "Start Uncomoress"
tar xzf jdk-8u212-linux-x64.tar.gz
echo "Start Creat Jdk lib & Copy File"
mkdir $Jvm_lib
cp -r $temp_jdk_path $Jvm_lib
echo "Handle $profile_path"
touch $profile_path
echo "export J2SDKDIR=$jdk_path" > $profile_path
echo "export J2REDIR=$jdk_path/jre" >> $profile_path
echo "export PATH=\$PATH:$jdk_path/bin:$jdk_path/db/bin:$jdk_path/jre/bin" >> $profile_path
echo "export JAVA_HOME=$jdk_path" >> $profile_path
echo "export DERBY_HOME=$jdk_path/db" >> $profile_path
chmod +x $profile_path
source "/etc/profile"
echo "Config update-alternatives"
update-alternatives --install /usr/bin/java java $jdk_path/bin/java expr $jdk_num + 1
update-alternatives --install /usr/bin/jar jar $jdk_path/bin/jar expr $jdk_num + 1
update-alternatives --install /usr/bin/javac javac $jdk_path/bin/javac expr $jdk_num + 1
update-alternatives --config java
update-alternatives --config jar
update-alternatives --config javac
echo "Is success ?"
java -version
下载链接
https://dmca.makiras.org/Remote/jdk-8u212-linux-x64.tar.gz
一键命令
bash <(curl https://shell.makiras.org/bash/install-jdk-1.8.sh)
原理
我猜你不需要所以就不写了,对着命令百度就行了。