地址:http://www.allopopo.cn/?p=347
至今任然在继续使用ubuntu 10.04版,自认为是到目前为止ubuntu最稳定的版本。新的11.04有做尝试,但是实在是无法习惯unity,故放弃。
ubuntu默认自带的是openjdk,一般的使用已经足够,但是有的人出于莫名的理由,还是习惯使用sun jdk,也就是现在的oracle jdk。这篇文章简单地记录了在ubuntu下安装新版jdk7的几个步骤。原文出处在:Intalling Java 7 on Ubuntu Natty (11.04),经测试,该方法在10.04.3中也可以使用。
首先自然是去java的官网下载jdk7,这里我下载的是64位的jdk-7u1-linux-x64.tar.gz,另外还有32位版本的jdk- 7u1-linux-i586.tar.gz,根据你自己的需要来下载。下载完毕以后就前往下载目录解压,并且移动至系统的java虚拟机目录。
1
2
3
|
laharl@netherworld:~$
cd
Download
laharl@netherworld:~
/Download
$
tar
xf jdk-7u1-linux-x64.
tar
.gz
laharl@netherworld:~
/Download
$
sudo
mv
jdk1.7.0
/usr/lib/jvm/
|
目录移动完成之后,在java虚拟机的目录下面为jdk7创建一个链接,以便记忆:
1
2
|
laharl@netherworld:~
/Download
$
cd
/usr/lib/jvm
laharl@netherworld:
/usr/lib/jvm
$
sudo
ln
-s
/usr/lib/jvm/jdk1
.7.0
/usr/lib/jvm/java-7-sun
|
接着就在/usr/lib/jvm/下创建一个隐藏文件.java-7-sun.jinfo,将下列内容复制进入、保存:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
name=java-7-sun
alias
=java-7-sun
priority=63
section=non-
free
jre ControlPanel
/usr/lib/jvm/java-7-sun/jre/bin/ControlPanel
jre java
/usr/lib/jvm/java-7-sun/jre/bin/java
jre java_vm
/usr/lib/jvm/java-7-sun/jre/bin/java_vm
jre javaws
/usr/lib/jvm/java-7-sun/jre/bin/javaws
jre jcontrol
/usr/lib/jvm/java-7-sun/jre/bin/jcontrol
jre keytool
/usr/lib/jvm/java-7-sun/jre/bin/keytool
jre pack200
/usr/lib/jvm/java-7-sun/jre/bin/pack200
jre policytool
/usr/lib/jvm/java-7-sun/jre/bin/policytool
jre rmid
/usr/lib/jvm/java-7-sun/jre/bin/rmid
jre rmiregistry
/usr/lib/jvm/java-7-sun/jre/bin/rmiregistry
jre unpack200
/usr/lib/jvm/java-7-sun/jre/bin/unpack200
jre orbd
/usr/lib/jvm/java-7-sun/jre/bin/orbd
jre servertool
/usr/lib/jvm/java-7-sun/jre/bin/servertool
jre tnameserv
/usr/lib/jvm/java-7-sun/jre/bin/tnameserv
jre jexec
/usr/lib/jvm/java-7-sun/jre/lib/jexec
jdk appletviewer
/usr/lib/jvm/java-7-sun/bin/appletviewer
jdk apt
/usr/lib/jvm/java-7-sun/bin/apt
jdk extcheck
/usr/lib/jvm/java-7-sun/bin/extcheck
jdk idlj
/usr/lib/jvm/java-7-sun/bin/idlj
jdk jar
/usr/lib/jvm/java-7-sun/bin/jar
jdk jarsigner
/usr/lib/jvm/java-7-sun/bin/jarsigner
jdk java-rmi.cgi
/usr/lib/jvm/java-7-sun/bin/java-rmi
.cgi
jdk javac
/usr/lib/jvm/java-7-sun/bin/javac
jdk javadoc
/usr/lib/jvm/java-7-sun/bin/javadoc
jdk javah
/usr/lib/jvm/java-7-sun/bin/javah
jdk javap
/usr/lib/jvm/java-7-sun/bin/javap
jdk jconsole
/usr/lib/jvm/java-7-sun/bin/jconsole
jdk jdb
/usr/lib/jvm/java-7-sun/bin/jdb
jdk jhat
/usr/lib/jvm/java-7-sun/bin/jhat
jdk jinfo
/usr/lib/jvm/java-7-sun/bin/jinfo
jdk jmap
/usr/lib/jvm/java-7-sun/bin/jmap
jdk jps
/usr/lib/jvm/java-7-sun/bin/jps
jdk jrunscript
/usr/lib/jvm/java-7-sun/bin/jrunscript
jdk jsadebugd
/usr/lib/jvm/java-7-sun/bin/jsadebugd
jdk jstack
/usr/lib/jvm/java-7-sun/bin/jstack
jdk jstat
/usr/lib/jvm/java-7-sun/bin/jstat
jdk jstatd
/usr/lib/jvm/java-7-sun/bin/jstatd
jdk native2ascii
/usr/lib/jvm/java-7-sun/bin/native2ascii
jdk rmic
/usr/lib/jvm/java-7-sun/bin/rmic
jdk schemagen
/usr/lib/jvm/java-7-sun/bin/schemagen
jdk serialver
/usr/lib/jvm/java-7-sun/bin/serialver
jdk wsgen
/usr/lib/jvm/java-7-sun/bin/wsgen
jdk wsimport
/usr/lib/jvm/java-7-sun/bin/wsimport
jdk xjc
/usr/lib/jvm/java-7-sun/bin/xjc
plugin xulrunner-1.9-javaplugin.so
/usr/lib/jvm/java-7-sun/jre/lib/amd64/libnpjp2
.so
plugin mozilla-javaplugin.so
/usr/lib/jvm/java-7-sun/jre/lib/amd64/libnpjp2
.so
|
自己注意将amd64替换成i386,如果你使用的是32位版本。
最后就是配置了,就用gedit建一个文件,例如:java-7-config.sh,将下面的脚本复制进入文件,然后保存:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
update-alternatives --quiet --
install
/usr/lib/xulrunner-addons/plugins/libjavaplugin
.so xulrunner-1.9-javaplugin.so
/usr/lib/jvm/java-7-sun/jre/lib/amd64/libnpjp2
.so 63
update-alternatives --quiet --
install
/usr/lib/mozilla/plugins/libjavaplugin
.so mozilla-javaplugin.so
/usr/lib/jvm/java-7-sun/jre/lib/amd64/libnpjp2
.so 63
update-alternatives --quiet --
install
/usr/bin/appletviewer
appletviewer
/usr/lib/jvm/java-7-sun/bin/appletviewer
63 --slave
/usr/share/man/man1/appletviewer
.1 appletviewer.1
/usr/lib/jvm/java-7-sun/man/man1/appletviewer
.1
update-alternatives --quiet --
install
/usr/bin/apt
apt
/usr/lib/jvm/java-7-sun/bin/apt
63 --slave
/usr/share/man/man1/apt
.1 apt.1
/usr/lib/jvm/java-7-sun/man/man1/apt
.1
update-alternatives --quiet --
install
/usr/bin/extcheck
extcheck
/usr/lib/jvm/java-7-sun/bin/extcheck
63 --slave
/usr/share/man/man1/extcheck
.1 extcheck.1
/usr/lib/jvm/java-7-sun/man/man1/extcheck
.1
update-alternatives --quiet --
install
/usr/bin/idlj
idlj
/usr/lib/jvm/java-7-sun/bin/idlj
63 --slave
/usr/share/man/man1/idlj
.1 idlj.1
/usr/lib/jvm/java-7-sun/man/man1/idlj
.1
update-alternatives --quiet --
install
/usr/bin/jar
jar
/usr/lib/jvm/java-7-sun/bin/jar
63 --slave
/usr/share/man/man1/jar
.1 jar.1
/usr/lib/jvm/java-7-sun/man/man1/jar
.1
update-alternatives --quiet --
install
/usr/bin/jarsigner
jarsigner
/usr/lib/jvm/java-7-sun/bin/jarsigner
63 --slave
/usr/share/man/man1/jarsigner
.1 jarsigner.1
/usr/lib/jvm/java-7-sun/man/man1/jarsigner
.1
update-alternatives --quiet --
install
/usr/bin/javac
javac
/usr/lib/jvm/java-7-sun/bin/javac
63 --slave
/usr/share/man/man1/javac
.1 javac.1
/usr/lib/jvm/java-7-sun/man/man1/javac
.1
update-alternatives --quiet --
install
/usr/bin/javadoc
javadoc
/usr/lib/jvm/java-7-sun/bin/javadoc
63 --slave
/usr/share/man/man1/javadoc
.1 javadoc.1
/usr/lib/jvm/java-7-sun/man/man1/javadoc
.1
update-alternatives --quiet --
install
/usr/bin/javah
javah
/usr/lib/jvm/java-7-sun/bin/javah
63 --slave
/usr/share/man/man1/javah
.1 javah.1
/usr/lib/jvm/java-7-sun/man/man1/javah
.1
update-alternatives --quiet --
install
/usr/bin/javap
javap
/usr/lib/jvm/java-7-sun/bin/javap
63 --slave
/usr/share/man/man1/javap
.1 javap.1
/usr/lib/jvm/java-7-sun/man/man1/javap
.1
update-alternatives --quiet --
install
/usr/bin/jconsole
jconsole
/usr/lib/jvm/java-7-sun/bin/jconsole
63 --slave
/usr/share/man/man1/jconsole
.1 jconsole.1
/usr/lib/jvm/java-7-sun/man/man1/jconsole
.1
update-alternatives --quiet --
install
/usr/bin/jdb
jdb
/usr/lib/jvm/java-7-sun/bin/jdb
63 --slave
/usr/share/man/man1/jdb
.1 jdb.1
/usr/lib/jvm/java-7-sun/man/man1/jdb
.1
update-alternatives --quiet --
install
/usr/bin/jhat
jhat
/usr/lib/jvm/java-7-sun/bin/jhat
63 --slave
/usr/share/man/man1/jhat
.1 jhat.1
/usr/lib/jvm/java-7-sun/man/man1/jhat
.1
update-alternatives --quiet --
install
/usr/bin/jinfo
jinfo
/usr/lib/jvm/java-7-sun/bin/jinfo
63 --slave
/usr/share/man/man1/jinfo
.1 jinfo.1
/usr/lib/jvm/java-7-sun/man/man1/jinfo
.1
update-alternatives --quiet --
install
/usr/bin/jmap
jmap
/usr/lib/jvm/java-7-sun/bin/jmap
63 --slave
/usr/share/man/man1/jmap
.1 jmap.1
/usr/lib/jvm/java-7-sun/man/man1/jmap
.1
update-alternatives --quiet --
install
/usr/bin/jps
jps
/usr/lib/jvm/java-7-sun/bin/jps
63 --slave
/usr/share/man/man1/jps
.1 jps.1
/usr/lib/jvm/java-7-sun/man/man1/jps
.1
update-alternatives --quiet --
install
/usr/bin/jrunscript
jrunscript
/usr/lib/jvm/java-7-sun/bin/jrunscript
63 --slave
/usr/share/man/man1/jrunscript
.1 jrunscript.1
/usr/lib/jvm/java-7-sun/man/man1/jrunscript
.1
update-alternatives --quiet --
install
/usr/bin/jsadebugd
jsadebugd
/usr/lib/jvm/java-7-sun/bin/jsadebugd
63 --slave
/usr/share/man/man1/jsadebugd
.1 jsadebugd.1
/usr/lib/jvm/java-7-sun/man/man1/jsadebugd
.1
update-alternatives --quiet --
install
/usr/bin/jstack
jstack
/usr/lib/jvm/java-7-sun/bin/jstack
63 --slave
/usr/share/man/man1/jstack
.1 jstack.1
/usr/lib/jvm/java-7-sun/man/man1/jstack
.1
update-alternatives --quiet --
install
/usr/bin/jstat
jstat
/usr/lib/jvm/java-7-sun/bin/jstat
63 --slave
/usr/share/man/man1/jstat
.1 jstat.1
/usr/lib/jvm/java-7-sun/man/man1/jstat
.1
update-alternatives --quiet --
install
/usr/bin/jstatd
jstatd
/usr/lib/jvm/java-7-sun/bin/jstatd
63 --slave
/usr/share/man/man1/jstatd
.1 jstatd.1
/usr/lib/jvm/java-7-sun/man/man1/jstatd
.1
update-alternatives --quiet --
install
/usr/bin/native2ascii
native2ascii
/usr/lib/jvm/java-7-sun/bin/native2ascii
63 --slave
/usr/share/man/man1/native2ascii
.1 native2ascii.1
/usr/lib/jvm/java-7-sun/man/man1/native2ascii
.1
update-alternatives --quiet --
install
/usr/bin/rmic
rmic
/usr/lib/jvm/java-7-sun/bin/rmic
63 --slave
/usr/share/man/man1/rmic
.1 rmic.1
/usr/lib/jvm/java-7-sun/man/man1/rmic
.1
update-alternatives --quiet --
install
/usr/bin/schemagen
schemagen
/usr/lib/jvm/java-7-sun/bin/schemagen
63 --slave
/usr/share/man/man1/schemagen
.1 schemagen.1
/usr/lib/jvm/java-7-sun/man/man1/schemagen
.1
update-alternatives --quiet --
install
/usr/bin/serialver
serialver
/usr/lib/jvm/java-7-sun/bin/serialver
63 --slave
/usr/share/man/man1/serialver
.1 serialver.1
/usr/lib/jvm/java-7-sun/man/man1/serialver
.1
update-alternatives --quiet --
install
/usr/bin/wsgen
wsgen
/usr/lib/jvm/java-7-sun/bin/wsgen
63 --slave
/usr/share/man/man1/wsgen
.1 wsgen.1
/usr/lib/jvm/java-7-sun/man/man1/wsgen
.1
update-alternatives --quiet --
install
/usr/bin/wsimport
wsimport
/usr/lib/jvm/java-7-sun/bin/wsimport
63 --slave
/usr/share/man/man1/wsimport
.1 wsimport.1
/usr/lib/jvm/java-7-sun/man/man1/wsimport
.1
update-alternatives --quiet --
install
/usr/bin/xjc
xjc
/usr/lib/jvm/java-7-sun/bin/xjc
63 --slave
/usr/share/man/man1/xjc
.1 xjc.1
/usr/lib/jvm/java-7-sun/man/man1/xjc
.1
update-alternatives --quiet --
install
/usr/bin/java-rmi
.cgi java-rmi.cgi
/usr/lib/jvm/java-7-sun/bin/java-rmi
.cgi 63
update-alternatives --quiet --
install
/usr/bin/ControlPanel
ControlPanel
/usr/lib/jvm/java-7-sun/jre/bin/ControlPanel
63
update-alternatives --quiet --
install
/usr/bin/java
java
/usr/lib/jvm/java-7-sun/jre/bin/java
63
update-alternatives --quiet --
install
/usr/bin/java_vm
java_vm
/usr/lib/jvm/java-7-sun/jre/bin/java_vm
63
update-alternatives --quiet --
install
/usr/bin/javaws
javaws
/usr/lib/jvm/java-7-sun/jre/bin/javaws
63
update-alternatives --quiet --
install
/usr/bin/jcontrol
jcontrol
/usr/lib/jvm/java-7-sun/jre/bin/jcontrol
63
update-alternatives --quiet --
install
/usr/bin/keytool
keytool
/usr/lib/jvm/java-7-sun/jre/bin/keytool
63
update-alternatives --quiet --
install
/usr/bin/pack200
pack200
/usr/lib/jvm/java-7-sun/jre/bin/pack200
63
update-alternatives --quiet --
install
/usr/bin/policytool
policytool
/usr/lib/jvm/java-7-sun/jre/bin/policytool
63
update-alternatives --quiet --
install
/usr/bin/rmid
rmid
/usr/lib/jvm/java-7-sun/jre/bin/rmid
63
update-alternatives --quiet --
install
/usr/bin/rmiregistry
rmiregistry
/usr/lib/jvm/java-7-sun/jre/bin/rmiregistry
63
update-alternatives --quiet --
install
/usr/bin/unpack200
unpack200
/usr/lib/jvm/java-7-sun/jre/bin/unpack200
63
update-alternatives --quiet --
install
/usr/bin/orbd
orbd
/usr/lib/jvm/java-7-sun/jre/bin/orbd
63
update-alternatives --quiet --
install
/usr/bin/servertool
servertool
/usr/lib/jvm/java-7-sun/jre/bin/servertool
63
update-alternatives --quiet --
install
/usr/bin/tnameserv
tnameserv
/usr/lib/jvm/java-7-sun/jre/bin/tnameserv
63
update-alternatives --quiet --
install
/usr/bin/jexec
jexec
/usr/lib/jvm/java-7-sun/jre/lib/jexec
63
|
还是老样子,如果你使用的是32位的jdk,则将脚本内的amd64替换成i386。
最后运行脚本:
1
|
laharl@netherworld:~$
sudo
sh java-7-config.sh
|
收工,接下去就是设置你当前使用的jdk版本。查看目前系统内安装的jdk,使用命令:
1
|
laharl@netherworld:~$ update-java-alternatives --list
|
设置当前系统使用的jdk,例如我们需要设置成我们刚刚安装的java-7-sun,则使用命令:
1
|
laharl@netherworld:~$ update-java-alternatives --
set
java-7-sun
|
最后用
1
|
laharl@netherworld:~$ java -version
|
查看当前jdk版本,如果显示是1.7,则表示安装成功。然后还可以开firefox去网上搜个applet运行一下看看浏览器插件是否安装成功。