From:http://www.cnblogs.com/plinx/archive/2013/06/01/3113106.html
1, to the Sun's official website download
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Select Accept License and select the JDK download that fits your model.
2, unzip the file, modify the filename
mkdir/usr/lib/tar zxvf jdk-7u21-linux-i586. Tar.gz-c/usr/lib/jvm$ cd/usr/lib/mv Jdk1. 7.0_21 java
3. Add Environment variables
sudo vim ~/.BASHRC
Add the following:
Export java_home=/usr/lib/jvm/JAVA export jre_home=${java_home}/JRE export classpath=.:${java_home}/ lib:${jre_home}/Lib export path=${java_home}/bin: $PATH
4. Configuring the default JDK version
sudo update-alternatives--install/usr/bin/java Java/usr/lib/jvm/java/bin/java 300 sudo Update-alternatives--install/usr/bin/javac Javac/usr/lib/jvm/java/bin/javac 300 sudo update-alternatives--install/usr/bin/jar Jar/usr/lib/jvm/java/bin/jar 300 sudo Update-alternatives--install/usr/bin/javah Javah/usr/lib/jvm/java/bin/javah 300 sudo update-alternatives--install/usr/bin/javap JAVAP/USR/LIB/JVM/JAVA/BIN/JAVAP 300
And then execute
sudo update-alternatives--config java
If you first install the JDK, you will be prompted
In Link Group Java (providing/usr/bin/java):/usr/lib/jvm/java/bin/Java does not need to be configured.
For non-initial installation, there will be different versions of the JDK option.
5. Testing
$ java-"1.7.0_21"1.7.0_21-23.21-b01, mixed mode)
[Ubuntu Setup] Ubuntu 14.10 Installation JDK