linux 下卸载jdk重新安装配置JDK

一、jdk1.4卸载

RedhatEnterprise5中自带安装了jdk1.4,在安装jdk1.6前,把jdk1.4卸载:

1.首先查看系统自带的JDK版本:

[root@linux ~]# java -version
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-48)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2.确定JDK的具体版本号,然后将其卸载:

[root@linux ~]# rpm -qa | grep jdk
[root@linux ~]# rpm -qa | grep gcj
libgcj-4.1.2-42.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

上面先确认jdk的具体版本号,然后使用rpm-e--nodeps命令删除上面查找的内容:

#rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

Complete!

3.再次检查JDK版本,卸载成功:

[root@linux ~]# java -version

-bash: ./usr/bin/java: No such file or directory

二、jdk1.6安装

下面开始手动安装thelatestjdk1.6version,jdk-6u33-linux-i586.bin

1.给jdk-6u33-linux-i586.bin分配权限,具体的这里要给它可执行的权限

[root@linux~]#chmod+xjdk-6u33-linux-i586.bin

2.然后解压:./jdk-6u33-linux-i586.bin

[root@linux~]#./jdk-6u33-linux-i586.bin

3.执行之后会有一堆agreement什么的,一路more下去。接着有个确认安装的,输入yes,然后回车。开始解压。一直到

Java(TM)SEDevelopmentKit6successfullyinstalled.

.........

PressEntertocontinue.....

Done.

4.解压后的文件如下所示:

[root@linux~]#ls

jdk1.6.0_33jdk-6u33-linux-i586.bin

5.一般都将安装文件放在usr/local下,执行拷贝:

[root@linux ~]# mv jdk1.6.0_33 /usr/local
[root@linux ~]# cd /usr/local
[root@linux local]# ls
bin etc games include jdk1.6.0_33 lib libexec sbin share src

6.jdk已经成功搬运到了/usr/local下,然后就是最后一步,设置环境变量了。

7.这里有两种设置,一种是通过export设置临时生效,重启之后设置会丢失,一种是将设置写入/etc/profile文件中,可以一直生效。所以,最好的设置当然是写入文件中了。先执行下面命令:

[root@linuxlocal]#vi/etc/profile

8.打开profile文件后输入i进入insert模式,在文件最后面添加如下内容。

exportJAVA_HOME="/usr/local/jdk1.6.0_33"

exportCLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"

exportPATH=".:$PATH:$JAVA_HOME/bin"

然后esc,输入:wq,保存退出。

9.然后需要设置让更改生效:

[root@linux local]# source /etc/profile

当然,如果你喜欢重启的话,你reboot也可以。

10.查看当前jdk版本。

[root@linux local]# java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03)
Java HotSpot(TM) Client VM (build 20.8-b03, mixed mode, sharing)

安装完毕!

==========================================================

另一种方法:

[root@localhost ~]# yum remove java
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115 set to be erased
--> Processing Dependency: java-gcj-compat for package: antlr
--> Processing Dependency: java-gcj-compat for package: antlr
--> Processing Dependency: java-gcj-compat >= 1.0.64 for package: gjdoc
--> Processing Dependency: java-gcj-compat >= 1.0.64 for package: gjdoc
--> Running transaction check
---> Package antlr.i386 0:2.7.6-4jpp.2 set to be erased
---> Package gjdoc.i386 0:0.7.7-12.el5 set to be erased
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                                Arch                  Version                              Repository                  Size
====================================================================================================================================
Removing:
 java-1.4.2-gcj-compat                  i386                  1.4.2.0-40jpp.115                    installed                   441 
Removing for dependencies:
 antlr                                  i386                  2.7.6-4jpp.2                         installed                  2.5 M
 gjdoc                                  i386                  0.7.7-12.el5                         installed                  1.7 M

Transaction Summary
====================================================================================================================================
Remove        3 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)

Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing        : antlr                                                                                                        1/3 
  Erasing        : gjdoc                                                                                                        2/3 
  Erasing        : java-1.4.2-gcj-compat                                                                                        3/3 

Removed:
  java-1.4.2-gcj-compat.i386 0:1.4.2.0-40jpp.115                                                                                    

Dependency Removed:
  antlr.i386 0:2.7.6-4jpp.2                                        gjdoc.i386 0:0.7.7-12.el5                                       

Complete!

相关推荐