一 卸载:
(1)查看Java版本:
1
2
3
4
|
[root@prx02 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包:
1
2
3
4
5
6
7
8
|
[root@prx02 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相关的包:
1
2
3
|
[root@prx02 src]
# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.101-2.6.6.1.el7_2.x86_64
[root@prx02 src]
# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64
[root@prx02 src]
# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.91-0.b14.el7_2.x86_64
|
(4)卸载完成后再次查看jdk版本:
1
2
|
[root@prx02 src]
# java -version
-
bash
:
/usr/bin/java
: No such
file
or directory
|
可以发现,现在是显示未安装状态的。至此,openjdk全部卸载完成
二 安装Sun JDK
(1)下载jdk的rpm包,并进行安装:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@prx02 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
[root@prx02 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的环境变量:
1
|
[root@prx02 src]
# vim /etc/profile
|
进入这个文件后找到export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC,在该语句的上面添加以下语句:
1
2
3
|
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路径来设置。当然,可以使用这个命令来查找:
1
|
[root@prx02 src]
# which java
|
编辑完成之后,按Esc返回命令模式,然后保存退出
(3)在不重启服务器的情况下更新配置:
1
|
[root@prx02 src]
# source /etc/profile
|
(4)最后效果如下:
1
2
3
4
|
[root@prx02 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)
|
到此,全部配置完成
本文转自 pangfc 51CTO博客,原文链接:http://blog.51cto.com/983836259/1773600,如需转载请自行联系原作者