- 环境:Cent OS 7
- JDK版本:jdk-8u162-linux-x64.tar.gz
- [
链接:Baidu网盘
提取码:bngk
]
1、新建文件夹并复制JDK
[root@localhost etc]# mkdir /usr/local/java
# 复制jdk-7u80-linux-x64.tar.gz到/usr/local/java 下
2、移动到java目录下并解压
[root@localhost java]# cd /usr/local/java
[root@localhost java]# tar -zxvf jdk-8u162-linux-x64.tar.gz
3、备份配置文件
# 创建备份文件夹
[root@localhost etc]# mkdir /etc/a_backup_config
# 备份 [建议备份配置文件名格式:原文件名_backup_日期]
[root@localhost etc]# cp profile /etc/a_backup_config/profile_backup_20181211
4、配置环境变量
[root@localhost etc]# vi /etc/profile
# 进入编辑状态,按 G 将光标移动到最后一行,按 i 插入如下内容:
#set java environment
export JAVA_HOME=/usr/local/java/jdk1.8.0_162
export JAVA_BIN=/usr/local/java/jdk1.8.0_162/bin
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
5、使配置文件生效
[root@localhost etc]# source /etc/profile
6、检测Java环境是配置成功
[root@localhost etc]# java -version
# 如果安装成功,则返回结果:
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)