centos7一键安装jdk1.8 shell脚本

centos7一键安装jdk1.8 shell脚本

jdk1.8百度云下载地址

链接:https://pan.baidu.com/s/1j_s9aW1a-4THB6vnG2GW-Q
提取码:bexj

将此shell脚本与安装tar包放在同一目录下,运行此脚本进行自动化安装

vim install_java.sh

将如下脚本,复制进install_java.sh

#!/bin/bash

#1.Check if Java is installed
if type -p java; then
	echo "Java has been installed."
	exit 0
else
#2.Installed Java 
	tar -zxvf ./jdk-8u261-linux-x64.tar.gz -C /usr/local/
	mv /usr/local/jdk1.8.0_261  /usr/local/javaJDK
#3.Configure environment variables
	echo "JAVA_HOME=/usr/local/javaJDK
	PATH=\$JAVA_HOME/bin:\$PATH
	CLASSPATH=\$JAVA_HOME/jre/lib/ext:\$JAVA_HOME/lib/tools.jar
	export PATH JAVA_HOME CLASSPATH" >> /etc/profile

	source /etc/profile
	echo "setting path successful."

	java -version
	echo "installed successful."

fi

将文件加权

chmod +x install_java.sh

运行脚本文件,进行安装

./install_java.sh

手动验证是否安装成功

java -version

如下所示为安装成功

~]# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b12, mixed mode)

如有必要,可以进行重启再次验证,确保重启生效。

你可能感兴趣的:(shell,脚本,linux,centos,jdk1.8,shell)