下载文件: jdk-8u241-linux-x64.tar.gz
[root@localhost ~]# java -version java version "1.7.0_" OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
[root@localhost ~]# rpm -qa | grep java javapackages-tools-3.4.1-6.el7_0.noarch tzdata-java-2014i-1.el7.noarch java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64 java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64 python-javapackages-3.4.1-6.el7_0.noarch
[root@localhost ~]# rpm -e --nodeps tzdata-java-2014i-1.el7.noarch [root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64 [root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
执行完删除命令之后,再次执行java -version
命令 :
[root@localhost ~]# java -version bash: java: 未找到命令
说明原JDK版本已经被删除.
[root@localhost ~]# mkdir -p /usr/local/src/jdk [root@localhost ~]# cd /usr/local/src/jdk
[root@localhost jdk]# tar -zxvf jdk-8u231-linux-x64.tar.gz [root@localhost jdk]# mv jdk1.8.0_241 jdk1.8
[root@localhost jdk]# vi /etc/profile
进入配置文件后,在配置文件的最后面添加配置:
export JAVA_HOME=/usr/local/src/jdk/jdk1.8 export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
退出配置文件后执行命令
source /etc/profile
让配置文件立即生效
再次执行命令java -version
查看JDK是否安装成功
[root@localhost jdk]# java -version java version "1.8.0_241" Java(TM) SE Runtime Environment (build 1.8.0_241-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.241-b11, mixed mode)5 sudo: java: command not found