情景描述
Linux下安装jdk后还需要进一步配置环境变量,这里写了一个简单的脚本,用来解决手动安装配置的问题;
代码实现
在执行完脚本后,需要在shell中另外执行 " source /etc/profile",才能立即生效
代码位置:
-
#!/bin/bash
-
-
if [ $UID -ne 0 ];
-
then
-
echo "Please run with super user"
-
exit 1
-
fi
-
-
JDK_FILE="jdk-7u80-linux-x64.tar.gz"
-
JDK_DURL=""
-
JDK_INSTALL_DIR="/usr/local/java"
-
JDK_ROOT_FOLDER="jdk1.7.0_80"
-
JDK_STD_FOLDER="/usr/java"
-
PROFILE="/etc/profile"
-
-
if [ ! -f $JDK_FILE ]; then
-
wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" $JDK_DURL -O ./$JDK_FILE
-
fi
-
-
if [ $? -ne 0 ];
-
then
-
echo "Download $JDK_FILE failed."
-
exit 1
-
else
-
echo "Download $JDK_FILE success."
-
fi
-
-
if [ ! -f "$JDK_FILE" ];
-
then
-
echo "$JDK_FILE Not Found."
-
exit 1
-
fi
-
-
if [ ! -d "$JDK_INSTALL_DIR" ];
-
then
-
echo "ehll"
-
mkdir -p "$JDK_INSTALL_DIR"
-
fi
-
-
tar -zxvf $JDK_FILE -C $JDK_INSTALL_DIR
-
-
if [ ! -d "$JDK_STD_FOLDER" ];
-
then
-
mkdir -p "$JDK_STD_FOLDER"
-
fi
-
-
ln -s "$JDK_INSTALL_DIR/$JDK_ROOT_FOLDER" "$JDK_STD_FOLDER/jdk"
-
-
echo "JAVA_HOME=$JDK_STD_FOLDER/jdk" >> "$PROFILE"
-
echo "PATH=$JDK_STD_FOLDER/jdk/bin:$PATH" >> "$PROFILE"
-
echo "CLASSPATH=$JDK_STD_FOLDER/jdk/lib/rt.jar:$JDK_STD_FOLDER/jdk/lib/tools.jar" >> "$PROFILE"
-
source "$PROFILE"
-
-
java -version
阅读(2053) | 评论(0) | 转发(0) |