Ubuntu 11.10 安装 Sun JDK 7

一直想使用Sun JDK7来试试它的新功能,但是Ubuntu 11.10的apt-get只能安装OpenJDK,于是乎下载了一个JDK7,解压缩后设置好了JAVA_HOME,也把$JAVA_HOME/bin放到了$PATH下。结果java -version仍然是OpenJDK的……

我心就凉了。

是不是2个java在$PATH中冲突了?于是sudo apt-get autoremove openjdk-6-jre-headless掉OpenJDK,再次java,结果提示没有找到java……

我心就拔凉拔凉的了。

然后google了一圈发现了这篇文章

http://diegobenna.blogspot.com/2011/01/install-jdk-6-update-21-in-ubuntu-1010.html 需翻 墙。

看了一半我发现了/etc/alternatives,以前在找OpenJDK的时候发现java命令是连接到这个文件夹然后才连接到真正的安装目录的,当时忽略了这个事实,恍然大悟中……

JDK (Java Development Kit) is a software that provides development tools for creating Java programs.

Installation


First we must download the package from the java website, select your platform, in our case Linux:



http://www.oracle.com/technetwork/java/javase/downloads/index.html

Here we go down the file "jdk-6u21-linux-i586.bin" to any folder, then leave where appropriate.

Now we have to give execute permissions:
sudo chmod +x jdk-6u23-linux-i586.bin

and install:
sudo ./jdk-6u23-linux-i586.bin

Now move the generated folder to a more appropriate directory:
sudo mv jdk1.6.0_23/ /usr/local

We set the new Java as one of the alternatives "java"
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/jdk1.6.0_23/bin/java" 1

Now we set the "new alternative" as real Java. This step makes the sun is the version used by default:
sudo update-alternatives --set java /usr/local/jdk1.6.0_23/bin/java

Now we do the same steps above for javac:

sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/jdk1.6.0_23/bin/javac" 1
sudo update-alternatives --set javac /usr/local/jdk1.6.0_23/bin/javac



Now verify that everything works properly. Open the console and type:
java -version

If all is well, you should return the following:

java version "1.6.0_23"
Java (TM) SE Runtime Environment (build 1.6.0_23-B06)
Java HotSpot (TM) Client VM (build 17.0-b16, mixed mode, sharing)


For javac:
javac -version

If all is well back:
javac 1.6.0_23

If you have other installations of java / javac can be configured using the following commands:
sudo update-alternatives --config java
sudo update-alternatives --config javac


Also if you want setear JRE_HOME JAVA_HOME or as environment variables, we must go to:
sudo gedit /etc/environment

Here we record the routes where we have installed Java, in our case is as follows:
JAVA_HOME = "/usr/local/jdk1.6.0_23/bin/" (add)
JRE_HOME = "/usr/local/jdk1.6.0_23/jre" (add)
PATH ="...(other routes):$JAVA_HOME:$JRE_HOME (edit)


With this we finish the installation.

还有一篇文章是说安装tomcat的:

http://diegobenna.blogspot.com/2011/01/install-tomcat-7-in-ubuntu-1010.html

猜你喜欢

转载自huadi223.iteye.com/blog/1262576
今日推荐