问题描述
如何在Ubuntu 12.04上安装Java?
我有:
-
Java(TM)SE运行时环境(版本1.7.0_21-b11)
-
Java HotSpot(TM)64位服务器VM(版本23.21-b01,混合模式)
最佳解决方法
要安装最新版本的Oracle Java(最新发布在Oracle网页上),最简单的方法是使用Java Installer(如flashplugin-installer那样),如下所示:http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
Oracle JDK7 itself is not hosted in the PPA because that’s not allowed by the new Java license (which is also the reason why it has been removed from the official Ubuntu repositories); the package in the PPA automatically downloads (and installs) Oracle Java JDK 7 from its official website and installs it on your computer, just like the flashplugin-installer package does.
然后,你必须只做这个:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
并输入以检查版本:
java -version
次佳解决方法
PPA不是一种安全/智能的安装方式。安装JDK非常简单直接。
步骤如下:
从Oracle网站下载最新的jdk并提取:
tar -xvf jdk-7u51-linux-x64.tar.gz
mkdir -p /usr/lib/jvm
mv ./jdk1.7.0_51/ /usr/lib/jvm/jdk1.7.0_51/
创建一些符号链接:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_51/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_51/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_51/bin/javaws" 1
类似地,可以为JAVA的其他命令创建符号链接。其他可用的命令是:
appletviewer,apt,extcheck,idlj,jar,jarsigner,javadoc,javafxpackager,javah,javap,java-rmi.cgi,jcmd,jconsole,jcontrol,jdb,jhat,jinfo,jmap,jmc,jps,jrunscript,jsadebugd,jstack,jstat,jstatd,jvisualvm,keytool,native2ascii,orbd,pack200,policytool,rmic,rmid,rmiregistry,schemagen,serialver,servertool,tnameserv,unpack200,wsgen,wsimport,xjc
确保合适的用户拥有正确的权限:
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0