大多Linux系统安装完成有默认自带的JDK,如下可以查看是否安装了JDK:
[root@localhost ~]# java -version
1 卸载jdk
(1) 输入 rpm -qa | grep gcj 回车
[root@localhost ~]# rpm -qa | grep gcj
libgcj-4.1.2-52.el5
libgcj-4.1.2-52.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
(2) 卸载以java开头的文件,输入命令: rpm -e --nodeps java-1.4.2-gci... 回车
[root@localhost ~]# rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
如果有相同的文件名,则输入: rpm -e --nodeps --allmatches java-1.4.2-gci... 回车,卸载以java开头的;
2 打开SSH secure file文件,在usr下点击右键新建java文件夹,拷贝jdk-6u13-linux-i586.bin、jdk-6u13-linux-i586-rpm.bin文件到java文件夹
3 给 jdk-6u13-linux-i586.bin授权
输入命令: (1)cd .. 回车 (2)cd java 回车 (3)chmod 755 jdk-6u13-linux-i586.bin 回车
4 解压和安装jdk-6u13-linux-i586.bin
输入命令:./jdk-6u13-linux-i586.bin 回车;长按回车,最后输入yes
[root@localhost java]# ./jdk-6u13-linux-i586.bin
Sun Microsystems, Inc. Binary Code License Agreement
for the JAVA SE DEVELOPMENT KIT (JDK), VERSION 6
SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THE
SOFTWARE IDENTIFIED BELOW TO YOU ONLY UPON THE CONDITION
.................................................................................................................
Please enter "yes" or "no".
Do you agree to the above license terms? [yes or no]
yes
Unpacking...
Checksumming...
The download file appears to be corrupted. Please refer
to the Troubleshooting section of the Installation
Instructions on the download page for more information.
Please do not attempt to install this archive file.
5 给 jdk-6u13-linux-i586-rpm.bin 授权
输入命令: chmod 755 jdk-6u13-linux-i586-rpm.bin 回车
6 解压和安装jdk-6u13-linux-i586-rpm.bin
输入命令:./jdk-6u13-linux-i586-rpm.bin 回车
执行此命令可能会出现如下错误:
Please enter "yes" or "no".
Do you agree to the above license terms? [yes or no]
yes
Unpacking...
Checksumming...
Extracting...
./jdk-6u13-linux-i586-rpm.bin: ./install.sfx.2795: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Installing JavaDB
error: open of sun-javadb-common-10.4.1-3.1.i386.rpm failed: No such file or directory
error: open of sun-javadb-core-10.4.1-3.1.i386.rpm failed: No such file or directory
error: open of sun-javadb-client-10.4.1-3.1.i386.rpm failed: No such file or directory
error: open of sun-javadb-demo-10.4.1-3.1.i386.rpm failed: No such file or directory
error: open of sun-javadb-docs-10.4.1-3.1.i386.rpm failed: No such file or directory
error: open of sun-javadb-javadoc-10.4.1-3.1.i386.rpm failed: No such file or directory
Done.
解决方法:
yum install mesa-libGL.i686
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u13-linux-i586.rpm
inflating: sun-javadb-common-10.4.1-3.1.i386.rpm
inflating: sun-javadb-core-10.4.1-3.1.i386.rpm
inflating: sun-javadb-client-10.4.1-3.1.i386.rpm
inflating: sun-javadb-demo-10.4.1-3.1.i386.rpm
inflating: sun-javadb-docs-10.4.1-3.1.i386.rpm
inflating: sun-javadb-javadoc-10.4.1-3.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]
Java(TM) SE Development Kit 6 successfully installed.
Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Sun products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the Sun Product Registration form for
the JDK will be presented. If you do not register, none of
this information will be saved. You may also register your
JDK later by opening the register.html file (located in
the JDK installation directory) in a browser.
For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html
Press Enter to continue.....
Done.
7 输入命令:rpm -ivh jdk-6u13-linux-i586.rpm 回车 (该命令和6等价,只是这是rpm安装,而6是自解压安装)
[root@localhost java]# rpm -ivh jdk-6u13-linux-i586.rpm
Preparing... ########################################### [100%]
package jdk-1.6.0_13-fcs.i586 is already installed
[root@localhost java]#
8 配置环境变量
(1)输入命令:vi /etc/profile 回车
(2)光标移到最后一位,点击 i 键变为输入模式
(3)换行粘贴以下字段:
export JAVA_HOME=/usr/java/jdk1.6.0_13
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
(4)按Esc键,输入:wq保存退出
(5)执行source /etc/profile 使环境变量生效,如果不执行此步骤,则跳转到9,重启系统;
9 重启系统输入命令:reboot 回车
10 输入java、javac、java -version等信息验证是否安装成功,如果成功则版本号为1.6.0_13则安装成功;
Java 卸载
有两种方法卸载 Java。请使用您在安装 Java 时所用的方法。例如,如果您以前使用 RPM 安装 Java,则使用 RPM 卸载方法。
RPM 卸载
注:如果您的 Linux 盒中具有 RPM,则应首先确定 Java 是否是使用 RPM 安装的。如果 Java 不是使用 RPM 安装的,则请跳过本节内容。
1.打开终端窗口
2.以超级用户身份登录
3.键入以下命令,尝试查找 JRE 软件包: rpm -qa
4.如果 RPM 报告一个类似于 jre-<version>-fcs 的软件包,则说明 Java 是使用 RPM 安装的。
注:通常,您不必使用 RPM 卸载 Java,因为 RPM 可以在安装新版本时自动卸载旧版本的 Java!除非您准备永久删除 Java,否则请跳过本节内容。
5.要卸载 Java,请键入: rpm -e jre-<version>-fcs
自解压文件卸载
1.确定 Java 是否安装在某些文件夹中。常用位置包括 /usr/java/jre_<version> 或 /opt/jre_nb/jre_<version>/bin/java/
2.如果找到了安装 Java 的文件夹,可以删除此文件夹。
警告:删除文件夹之前,应确保 Java 以前不是使用 RPM 安装的。
3.键入: rm -r jre<version>
例如: rm -r jre1.7.0
详见官网:http://www.java.com/zh_CN/download/help/linux_uninstall.xml