在CentOS7上安装与设置JDK1.8

1 通过 SecureCRT 连接到阿里云 CentOS7 服务器;

2 进入到目录 /usr/local/ 中:
cd /usr/local/

3 创建目录 tools:
mkdir -p tools

4 进入到目录 /usr/local/tools 中:
cd tools/

5 下载 jdk-8u91-linux-x64.tar.gz:
wget –no-check-certificate –no-cookies –header “Cookie: Oraclelicense=accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm
wget –no-check-certificate –no-cookies –header “Cookie: oraclelicense=accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.tar.gz
wget –no-check-certificate –no-cookies –header “Cookie: oraclelicense=accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-x64.rpm
wget –no-cookies –header “Cookie: oraclelicense=accept-securebackup-cookie;” http://download.oracle.com/otn-pub/java/jdk/7u65-b17/jdk-7u65-linux-x64.tar
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.6.tgz
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.0.M4/bin/apache-tomcat-9.0.0.M4.tar.gz
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.12-1.el7.x86_64.rpm-bundle.tar
wget http://apache.fayea.com/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz
wget http://memcached.org/files/memcached-1.4.25.tar.gz

6 加压缩 jdk-8u91-linux-x64.tar.gz 文件:
tar -zxvf jdk-8u91-linux-x64.tar.gz

7 返回到上一级并创建 /usr/local/jdk 目录:
cd ..
mkdir -p jdk

8 进入到 tools 目录后将 jdk1.8.0_91 移动到 jdk 目录中:
cd ../tools/
mv jdk1.8.0_91/ ../jdk/

9 打开 /etc/ 目录下的 profile 文件:
vi /etc/profile
将如下代码追加到 profile 文件末尾:
# idea – jdk8 settings start 2016-05-01

JAVA_HOME=/usr/local/jdk/jdk1.8.0_91
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/dt.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH

# idea – jdk8 settings end – 2016-05-01
按 Esc 键、输入 wq! 回车,保持并退出。

10 即可启用新的配置:
source /etc/profile

11 输入 java -version 查看 JDK 的版本:
[root@iZ94hws2fzlZ jdk1.8.0_91]# java -version
java version “1.8.0_91”
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)