来自 http://www.devsniper.com/ubuntu-12-04-install-sun-jdk-6-7/
Ubuntu GNU/Linux 12.04 LTS (Precise Pangolin) released. I wanted to manually install the Sun JDK 6 and 7 on Ubuntu.
Updated for Ubuntu GNU/Linux 12.10 (Quantal Quetzal).
Installing Sun JDK 6 on Ubuntu 12.04 / 12.10:
chmod +x jdk-6u32-linux-x64.bin
./jdk-6u32-linux-x64.bin
sudo mv jdk1.6.0_38 /usr/lib/jvm/jdk1.6.0_38
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_38/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.6.0_38/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.6.0_38/bin/javaws 1
sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws
java -version
ls -la /etc/alternatives/java*
#for 64-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.6.0_38/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins #for 32-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.6.0_38/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Installing Sun JDK 7 on Ubuntu 12.04 / 12.10:
tar -xvzf jdk-7u11-linux-x64.tar.gz
sudo mv jdk1.7.0_11 /usr/lib/jvm/jdk1.7.0_11
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_11/bin/javac 1 sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_11/bin/java 1 sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_11/bin/javaws 1
sudo update-alternatives --config javac sudo update-alternatives --config java sudo update-alternatives --config javaws
java -version
ls -la /etc/alternatives/java*
#for 64-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.7.0_11/jre/lib/amd64/libnpjp2.so /usr/lib/mozilla/plugins #for 32-Bit jdk sudo ln -s /usr/lib/jvm/jdk1.7.0_11/jre/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins
Update: I have added Java Web Start configuration (Thanks Jack).
Update: I have added Java Plugin configuration for Mozilla Firefox even for Chrome (Thanks shetty).
Update: JAVA_HOME configuration: Some tools require JAVA_HOME variable. You can set JAVA_HOME in Ubuntu so simple: Edit the file .bashrc under your home directory and add the following lines: (if .bashrc is hidden, click in Nautilus Menu View > Show Hidden Files)
export JAVA_HOME=/path/your/jdk export PATH=$JAVA_HOME/bin:$PATH