JDK安装

https://help.ubuntu.com/community/Java#Oracle_.28Sun.29_Java_6

  • oracle java 6 jdk 64-bit
 $ wget --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
 $ chmod u+x jdk-6u45-linux-x64.bin
 $ ./jdk-6u45-linux-x64.bin
 $ sudo mv jdk1.6.0_45 /opt
 $ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.6.0_45/bin/java" 1
 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk1.6.0_45/bin/javac" 1
 $ sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/opt/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so" 1
 $ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/jdk1.6.0_45/bin/javaws"
  • IMPORTANT choose the java you installed as default

 

 $ sudo update-alternatives --config java
 $ sudo update-alternatives --config javac
 $ sudo update-alternatives --config mozilla-javaplugin.so
 $ sudo update-alternatives --config javaws

Optionally you can set a JAVA_HOME env variable:

export _JAVA_HOME=/opt/jdk1.6.0_45/

 

Choosing the default Java to use

If your system has more than one version of Java, configure which one your system uses by entering the following command in a terminal window

sudo update-alternatives --config java

This will present you with a selection that looks similar to the following (the details may differ for you):

There are 2 choices for the alternative java (providing /usr/bin/java).  
Selection Path Priority Status 
———————————————————— 
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode 
1 /usr/lib/jvm/jre1.7.0/jre/bin/java 3 manual mode  

Press enter to keep the current choice[*], or type selection number: 1

ALL DONE. You can test your java install by

java -version

Here is a small screen capture of what happened on my screen when I went through above steps

Oracle JDK Install

Finally if you need to add JAVA_HOME variable, you can do so by adding it to the .bashrc file in your home directory

Open .bashrc file using an editor. If you use VI then
vi ~/.bashrc

and add the following 2 lines in your .bashrc file.

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21/
export JAVA_HOME

原文地址:https://www.cnblogs.com/zawn/p/3662363.html