#!/bin/bash
yum -y install wget
wget --no-cookies -P ~/ --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.tar.gz"
if [ ! -d "/usr/java" ]
then
mkdir /usr/java
fi
tar -zxvf ~/jdk-8u141-linux-x64.tar.gz -C /usr/java
# 修改环境变量 11 12 13
sed -i '12a\# 环境变量jdk' ~/.bashrc
sed -i '13a\export JAVA_HOME=/usr/java/jdk1.8.0_141' ~/.bashrc
sed -i '14a\export PATH=$PATH:$JAVA_HOME/bin' ~/.bashrc
source ~/.bashrc
java -version
echo $JAVA_HOME
1. 将脚本保存到本地 install-jdk.sh
2. 修改脚本权限 chmod 777 install-jdk.sh
3. 执行 ./install-jdk.sh
4. 刷新环境变量 source ~/.bashrc