CentOS下安装OracleJDK

获取OracleJDK

Java SE Development Kit 8u221为例,下载地址如下:

1
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

解压到目录

1
tar zxvf jdk-8u151-linux-x64.tar.gz -C /usr/jdk

配置环境变量

编辑**/etc/profile**文件,在最后添加如下内容:

1
2
3
4
export JAVA_HOME=/usr/jdk/jdk1.8.0_151
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

验证结果

1
2
3
4
# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)