1.执行Linux命令 -----vim /etc/profile  编辑profile  文件,在里面添加:

#set java enviroment
JAVA_HOME=/opt/JavaHome/jdk1.8.0_171
JRE_HOME=/opt/JavaHome/jdk1.8.0_171/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

2.执行Linux命令 --- source /etc/profile刷新修改后的配置文件

执行 java -version 查看安装的java版本
报错: bash: /home/jdk1.8.0_161/bin/java: Permission denied
[root@izuf6c6nw8nng69p6ui5mcz ~]# cd /opt/JavaHome/
[root@izuf6c6nw8nng69p6ui5mcz JavaHome]# ls
jdk1.8.0_171
[root@izuf6c6nw8nng69p6ui5mcz JavaHome]# java -version
-bash: /opt/JavaHome/jdk1.8.0_171/bin/java: Permission denied
[root@izuf6c6nw8nng69p6ui5mcz JavaHome]# chmod 777 jdk1.8.0_171/bin/java(重点)
[root@izuf6c6nw8nng69p6ui5mcz JavaHome]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)