概述
Linux上配置一个服务器环境,看了一下jdk的版本只有1.4,要换成1.6的,所以安装之前先得把jdk换成1.6的。
一、Linux版本:redhat
1、查看jdk的版本:
输入命令:java –version
返回:java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-44)
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、卸载jdk1.4
a)查看安装的jdk以及其依赖的文件
输入命令: [root@localhost ~]# rpm -qa|grep gcj
返回:
java-1.4.2-gcj-compat-src-1.4.2.0-40jpp.115
libgcj-src-4.1.2-44.el5
libgcj-devel-4.1.2-44.el5
libgcj-4.1.2-44.el5
java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115
java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
b)下面就卸载上述文件
[root@localhost ~]# rpm -e --nodeps java-1.4.2-gcj-compat-src-1.4.2.0-40jpp.115
[root@localhost ~]# rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
[root@localhost~]# rpm -e --nodeps java-1.4.2-gcj-compat-devel-1.4.2.0-40jpp.115
[root@localhost ~]# java -version
bash: /usr/bin/java: 没有那个文件或目录
3、安装jdk1.6
在http://java.sun.com/javase/downloads/index.jsp 下载jdk-6u37-linux-i586-rpm.bin放在/tmp目录下
[root@javasrv ~]# cd /usr/local/src
[root@javasrv src]# chmod 755 jdk-6u37-linux-i586-rpm.bin
[root@localhost src]# ./jdk-6u37-linux-i586-rpm.bin //安装后生成目录/usr/java
下面是自动安装过程:
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
replace jdk-6u37-linux-i586.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: jdk-6u37-linux-i586.rpm
replace sun-javadb-common-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-common-10.6.2-1.1.i386.rpm
replace sun-javadb-core-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-core-10.6.2-1.1.i386.rpm
replace sun-javadb-client-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-client-10.6.2-1.1.i386.rpm
replace sun-javadb-demo-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm
replace sun-javadb-docs-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm
replace sun-javadb-javadoc-10.6.2-1.1.i386.rpm? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
inflating: sun-javadb-javadoc-10.6.2-1.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...
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 Oracle products, services and training
* Access to early releases and documentation
Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form 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.
4、配置环境变量
环境变量配置有三种方法(分别是:修改/etc/profile文件,修改用户目录下的.bashrc文件,直接在shell下修改)
修改/etc/profile文件(系统级别有效)
[root@localhost src] # vi /etc/profile 加入下面几行:
JAVA_HOME=/usr/java/default
PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATH
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH
下面命令查看安装后的jdk版本:
[root@localhost src]# source /etc/profile
[root@localhost src]# java –version
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06)
Java HotSpot(TM) Client VM (build 20.12-b01, mixed mode, sharing)
5、测试配置环境
写个简单的HelloWorld来测试一下
[root@localhost ~]# vi HelloWorld.java
文件中输入:
public class HelloWorld {
public static void main(String args[]) {
System.out.println( " Hello World in Linux!! " );
}
}
按Esc键,然后是Shift+ : 键,wq 保存退出
[root@localhost ~]# javac HelloWorld.java
[root@localhost ~]# java HelloWorld
Hello World in Linux!!
成功完成了安装
二、Linux版本:Ubuntu 10.04
1.下载jdk,我选用的版本是jdk-6u41-linux-i586.bin,下载后放在/home目录下
2. 进入到/home目录下,并赋予用户管理员权限
命令:sudo -s
输入密码
3. 开始安装
(1)更改jdk-6u41-linux-i586.bin权限
命令:chmod chmod u+x jdk-6u41-linux-i586.bin
(2)运行jdk-6u41-linux-i586.bin
./ jdk-6u41-linux-i586.bin
4. 配置环境变量
(1)打开/etc/profile文件
命令:gedit /etc/profile
(2)加入下面环境变量
#set java environment
export JAVA_HOME=/home/jdk1.6.0_41
export JRE_HOME=/home/jdk1.6.0_41/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME:$PATH
一般更改/etc/profile文件后,需要重启机器才能生效。这里介绍一种不用重启使其生效的方法
命令:source /etc/profile
5. 查看java环境变量是否配置成功
命令:java -version
转载于:https://blog.51cto.com/6341986/1135698
最后
以上就是超级银耳汤为你收集整理的Linux安装jdk的全部内容,希望文章能够帮你解决Linux安装jdk所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复