原文地址:http://blog.csdn.net/gxy3509394/article/details/8166288 (感恩原文作者的分享)
最经公司需要在linux上开发、需要在linux系统上面搭建开发环境,倒腾了半个小时算是弄好了jdk的安装,写个博客记下来吧。
首先先检查linux机器上是否有自带的jdk
java -version检查下就可以,如果有版本低的话可以先卸载掉方法如下
[root@localhost java]# rpm -qa|grep gcj 或者 rpm -qa|grep java
libgcj-4.1.2-44.el5
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
如果没有信息就是没有安装、如果有那么如下操作
[root@localhost jdk-6u13-linux-i586]# yum -y remove java-1.4.2-gcj-compat-1.4.2.0-40jpp.115 或者 rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115Loaded 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
================================================================================
Install 0 Package(s)
Update 0 Package(s)
Remove 3 Package(s)
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!(看到这个说明完成了。。)
接着我们手动安装linux的jdk我的
下载地址
<a target=_blank target="_blank" href="http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html" style="color: rgb(202, 0, 0); text-decoration: none;">http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html</a>我下载的是rpm包
接着执行安装
[root@localhost local]# rpm -ivh jdk-7-linux-i586.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...
我的rpm包就这样就装好了。。
接着是配置环境变量
#vi /etc/profile
在该profile文件中最下面添加:
export JAVA_HOME=/usr/java/jdk1.7.0
export CLASSPATH=.:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$PATH
添加完毕保存退出
source /etc/profile
[root@localhost jdk1.7.0]# java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
[root@localhost jdk1.7.0]# echo $JAVA_HOME
/usr/java/jdk1.7.0
这个时候就大功告成了