参考:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/01/2994485.html
http://yinfeifei.iteye.com/blog/790571
一、安装JDK
1、yum方式
1.查找java相关得列表
[qyf@localhost ~]$ yum -y list java*
-
[qyf@localhost ~]$ yum -y list java*
-
Loaded plugins: fastestmirror
-
base | 1.1 kB 00:00
-
base/primary | 995 kB 00:00
-
base 2789/2789
-
extras | 2.1 kB 00:00
-
extras/primary_db | 164 kB 00:20
-
updates | 1.9 kB 00:00
-
updates/primary_db | 422 kB 00:01
-
Available Packages
-
java-1.4.2-gcj-compat.i386 1.4.2.0-40jpp.115 base
-
java-1.4.2-gcj-compat-devel.i386 1.4.2.0-40jpp.115 base
-
java-1.4.2-gcj-compat-javadoc.i386 1.4.2.0-40jpp.115 base
-
java-1.4.2-gcj-compat-src.i386 1.4.2.0-40jpp.115 base
-
java-1.6.0-openjdk.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
-
java-1.6.0-openjdk-demo.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
-
java-1.6.0-openjdk-devel.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
-
java-1.6.0-openjdk-javadoc.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
-
java-1.6.0-openjdk-src.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
-
java-1.7.0-openjdk.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
-
java-1.7.0-openjdk-demo.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
-
java-1.7.0-openjdk-devel.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
-
java-1.7.0-openjdk-javadoc.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
-
java-1.7.0-openjdk-src.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
-
java_cup.i386 1:0.10-0.k.6jpp.1 base
-
java_cup-javadoc.i386 1:0.10-0.k.6jpp.1 base
-
java_cup-manual.i386 1:0.10-0.k.6jpp.1 base
-
javacc.i386 4.0-3jpp.3 base
-
javacc-demo.i386 4.0-3jpp.3 base
-
javacc-manual.i386 4.0-3jpp.3 base
2.使用root用户安装
安装时提醒必须使用root用户,sudo都不行。
[qyf@localhost ~]$ yum -y install java-1.6.0-openjdk*
-
[qyf@localhost ~]$ yum -y install java-1.6.0-openjdk*
-
Loaded plugins: fastestmirror
-
Loading mirror speeds from cached hostfile
-
* base: mirror.bit.edu.cn
-
* extras: mirror.bit.edu.cn
-
* updates: centos.ustc.edu.cn
-
base | 1.1 kB 00:00
-
base/primary | 995 kB 00:07
-
base 2789/2789
-
extras | 2.1 kB 00:00
-
extras/primary_db | 164 kB 00:02
-
updates | 1.9 kB 00:00
-
updates/primary_db | 422 kB 00:07
-
Setting up Install Process
-
Resolving Dependencies
-
--> Running transaction check
-
---> Package java-1.6.0-openjdk.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
-
--> Processing Dependency: jpackage-utils >= 1.7.3-1jpp.2 for package: java-1.6.0-openjdk
-
--> Processing Dependency: libgif.so.4 for package: java-1.6.0-openjdk
-
--> Processing Dependency: tzdata-java for package: java-1.6.0-openjdk
-
---> Package java-1.6.0-openjdk-demo.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
-
---> Package java-1.6.0-openjdk-devel.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
-
---> Package java-1.6.0-openjdk-javadoc.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
-
---> Package java-1.6.0-openjdk-src.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
-
--> Running transaction check
-
---> Package giflib.i386 0:4.1.3-7.3.3.el5 set to be updated
-
---> Package jpackage-utils.noarch 0:1.7.3-1jpp.3.el5 set to be updated
-
---> Package tzdata-java.i386 0:2014b-1.el5 set to be updated
-
--> Finished Dependency Resolution
-
-
Dependencies Resolved
-
-
================================================================================
-
Package Arch Version Repository
-
Size
-
================================================================================
-
Installing:
-
java-1.6.0-openjdk i386 1:1.6.0.0-5.1.13.3.el5_10 updates 44 M
-
java-1.6.0-openjdk-demo i386 1:1.6.0.0-5.1.13.3.el5_10 updates 2.2 M
-
java-1.6.0-openjdk-devel i386 1:1.6.0.0-5.1.13.3.el5_10 updates 15 M
-
java-1.6.0-openjdk-javadoc i386 1:1.6.0.0-5.1.13.3.el5_10 updates 20 M
-
java-1.6.0-openjdk-src i386 1:1.6.0.0-5.1.13.3.el5_10 updates 39 M
-
Installing for dependencies:
-
giflib i386 4.1.3-7.3.3.el5 base 39 k
-
jpackage-utils noarch 1.7.3-1jpp.3.el5 base 60 k
-
tzdata-java i386 2014b-1.el5 updates 172 k
-
-
Transaction Summary
-
================================================================================
-
Install 8 Package(s)
-
Upgrade 0 Package(s)
-
-
Total download size: 120 M
-
Downloading Packages:
-
(1/8): giflib-4.1.3-7.3.3.el5.i386.rpm | 39 kB 00:00
-
(2/8): jpackage-utils-1.7.3-1jpp.3.el5.noarch.rpm | 60 kB 00:00
-
(3/8): tzdata-java-2014b-1.el5.i386.rpm | 172 kB 00:04
-
(4/8): java-1.6.0-openjdk-demo-1.6.0.0-5.1.13.3.el5_10.i386.rpm | 2.2 MB 00:47
-
(5/8): java-1.6.0-openjdk-devel-1.6.0.0-5.1.13.3.el5_10.i386.rpm | 15 MB 04:25
-
(6/8): java-1.6.0-openjdk-javadoc-1.6.0.0-5.1.13.3.el5_10.i386.rpm (17%) 19% [============ ] 81 kB/s | 3.8 MB 03:19 ETA
最后一行就是在下载jdk了,这里我们安装jdk1.6相关得全部包。
3.确认是否安装成功
[qyf@localhost ~]$ java -version
-
[qyf@localhost ~]$ java -version
-
java version "1.6.0_30"
-
OpenJDK Runtime Environment (IcedTea6 1.13.3) (rhel-5.1.13.3.el5_10-i386)
-
OpenJDK Client VM (build 23.25-b01, mixed mode)
正确显示了jdk版本信息就说明安装成功了。
4.默认情况下jdk安装得路径
/usr/lib/jvm
由于我们得机器可能同时安装好几个版本得jdk,所以在/etc/alternatives目录下会有一个java链接到具体的java命令。而这个/etc/alternatives/java会被/usr/bin/java链接。从而java命令就被设置到了shell环境中。
2、源码包方式
1 从官网上下载 jdk-7-linux-i586.tar.gz
选择这个包是因为可以适用于各个版本大linux, 而rpm只适用于redhat系列的linux.
2 解压此归档文件到/usr/local
tar -xvf jdk-7-linux-i586.tar.gz
mv jdk1.7.0 /usr/local
3 修改 /etc/profile, 配置环境变量,如果仅为当前用户设置环境变量则修改/home/XXX/.profile
添加:
export JAVA_HOME=/usr/local/jdk1.7.0
export JAVA_BIN=/usr/local/jdk1.7.0/bin
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
修改文件后要想马上生效还要运行$ source /etc/profile不然只能在下次重进此用户时生效。
4 测试环境变量是否正确
echo $JAVA_HOME
echo $JAVA_BIN
echo $PATH
echo $CLASSPATH
5 测试jdk是否安装成功
java -version
如果显示:
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
OK,大功告成
二、卸载JDK
1、卸载系统自带的jdk版本:
查看自带的jdk:
#rpm -qa|grep gcj
看到如下信息:
libgcj-4.1.2-44.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
使用rpm -e --nodeps 命令删除上面查找的内容:
#rpm -e –nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
2、卸载rpm安装的jkd版本
查看安装的jdk:
#rpm -qa|grep jdk
看到如下信息:
jdk-1.6.0_22-fcs
卸载:
#rpm -e --nodeps jdk-1.6.0_22-fcs
阅读(747) | 评论(0) | 转发(0) |