linux安装JDK
1. 将一键安装脚本install_JDK.sh与下载好的jdk1.7放到同一目录下,上传至linux服务器某一目录下
注:用脚本的目的,是方便与其它服务进行一键安装
2. 给install_JDK.sh增加执行权限
# chmod +x install_JDK.sh
3. 执行一键安装脚本
# ./install_JDK.sh
4.安装完成后验证
# java -version
5. 一键安装脚本的内容
#!/bin/sh
#获取当前路径
mypath=$(cd $(dirname $0)/; pwd)
function main()
{
#安装jdk
Install_JDK
sleep 1
echo "jdk安装完毕"
}
function Install_JDK()
{
jdk_path=/usr/jdk64/
profile=/etc/profile
java_home="export JAVA_HOME=/usr/jdk64/jdk1.7.0_67"
classpath="export CLASSPATH=.:\$JAVA_HOME/jre/lib/rt.jar:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar"
path="export PATH=.:\$JAVA_HOME/bin:\$PATH"
jdk_exists_path=$jdk_path/jdk1.7.0_67/
if [ -d "$jdk_exists_path" ]; then
return 1
fi
if [ ! -d /usr/jdk64 ];then
mkdir /usr/jdk64
fi
tar zxvf ${mypath}/jdk-7u67-linux-x64.tar.gz -C ${jdk_path}
echo $java_home >> $profile
echo $classpath >> $profile
echo $path >> $profile
source /etc/profile
. /etc/profile
sleep 1
#printf "check java version global.\n"
java -version
}
main