- 首先去官网下载jdk,选择自己要使用的版本
- https://www.oracle.com/java/technologies/javase-jdk11-downloads.html
- 检查当前系统是否已经安装openJDK,如果已经安装进行卸载
- 检查openJDK是否安装命令:rpm -qa|grep jdk
- 卸载命令:yum -y remove xxxx
- 进入目录 : cd /usr/local
- 创建java安装目录:mkdir /usr/local/java
- 解压安装包到 /usr/local/java目录: tar -zxvf jdk-11.0.7_linux-x64_bin.tar.gz /usr/local/java
- 配置jdk环境变量:
- 编辑/etc/下的profile文件: vi /etc/profile
- 在文件末尾添加如下配置:
export JAVA_HOME=/usr/local/java/jdk-11.0.7
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
- 使/etc/profile生效 :source /etc/profile
- 测试jdk安装是否成功: java -version
java version "11.0.7" 2020-04-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)