从http://java.sun.com中下载jdk:jdk-6u23-linux-i586.bin,存放到/usr/java目录
1、给权限:sudo chmod u+x /usr/java/jdk-6u23-linux-i586.bin
2、安装jdk:sudo /usr/java/jdk-6u23-linux-i586.bin
3、设置环境变量:sudo gedit /etc/environment
#set java environment
JAVA_HOME=/usr/java/jdk1.6.0_23
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH
export JAVA_HOME PATH CLASSPATH
4、使上面设置的环境变量生效:#source /etc/environment
5、设置ubuntu的默认jdk,原因使因为ubuntu默认有openjdk:
sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_23/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_23/bin/javac 300
sudo update-alternatives --config java
选择对应的jdk编号,回车
6、查看当前jdk版本:java -version