一 卸载:
(1)查看Java版本:
[[email protected] src]# java -version openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
(2)查询所有跟Java相关的安装的rpm包:
[[email protected] src]# rpm -qa | grep java tzdata-java-2016d-1.el7.noarch javapackages-tools-3.4.1-11.el7.noarch java-1.7.0-openjdk-headless-1.7.0.101-2.6.6.1.el7_2.x86_64 java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64 java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64 python-javapackages-3.4.1-11.el7.noarch java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
(3)卸载所有跟openjdk相关的包:
[[email protected] src]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64 [[email protected] src]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64 [[email protected] src]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
(4)卸载完成后再次查看jdk版本:
[[email protected] src]# java -version -bash: /usr/bin/java: No such file or directory
可以发现,现在是显示未安装状态的。至此,openjdk全部卸载完成
二 安装Sun JDK
(1)下载jdk的rpm包,并进行安装:
[[email protected] src]# ls apache-tomcat-h5.zip nginx-1.4.7.tar.gz pcre-8.36.tar.gz jdk-7u71-linux-x64.rpm Nginx_upstream_hash-0.3.1.tar.gz keepalived-1.2.2.tar.gz ngx_cache_purge-2.0.tar.gz [[email protected] src]# rpm -ivh jdk-7u71-linux-x64.rpm Preparing... ################################# [100%] Updating / installing... 1:jdk-2000:1.7.0_71-fcs ################################# [100%] Unpacking JAR files... rt.jar... jsse.jar... charsets.jar... tools.jar... localedata.jar... jfxrt.jar...
注:因为我这里已经事先下载好了,因此这里就直接安装了
(2)配置jdk的环境变量:
[[email protected] src]# vim /etc/profile
进入这个文件后找到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC,在该语句的上面添加以下语句:
export JAVA_HOME="/usr/java/jdk1.7.0_71" export CLASSPATH=".:/usr/java/jdk1.7.0_71/lib:/usr/java/jdk1.7.0_71/jre/lib" pathmunge /usr/java/jdk1.7.0_71/bin:/usr/java/jdk1.7.0_71/jre/bin
注:上面涉及的Java的路径要根据你自己的Java路径来设置。当然,可以使用这个命令来查找:
[[email protected] src]# which java
编辑完成之后,按Esc返回命令模式,然后保存退出
(3)在不重启服务器的情况下更新配置:
[[email protected] src]# source /etc/profile
(4)最后效果如下:
[[email protected] src]# java -version java version "1.7.0_71" Java(TM) SE Runtime Environment (build 1.7.0_71-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
到此,全部配置完成
时间: 2024-10-25 06:50:43