1、浏览器输入http://www.oracle.com/technetwork/java/javase/downloads/index.html,选择要下载的jdk,我是jdk6u45_linux_i586.bin,下载之后保存在默认的文件夹中,我这里是/home/vko/Download
2、用超级用户登录,输入如下命令sudo cp /home/vko/Download/jdk6u45_linux_i586.bin /usr/lib/java将下下来的jdk保存到/usr/lib/java中
3、安装jdk,先赋予可运行权限,在/usr/lib/java 中执行:sudo chmod u+x jdk6u45_linux_i586.bin,然后执行:sudo ./jdk6u45_linux_i586.bin开始安装
4、配置jdk环境变量,sudo gedit /etc/profile,在文件最后加入如下:
export JAVA_HOME=/usr/lib/java/jdk1.6.0_45
export JRE_PATH=/usr/lib/java/jdk1.6.0_45
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
然后保存关闭
5、使用source更新下profile
sudo source ~/.profile
6、修改系统默认jdk
sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jdk1.6.0_45/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/java/jdk1.6.0_45/bin/javac 300
sudo update-alertnatives --config java
sudo update-alternatives --config javac
7、验证是否安装成功,输入:sudo java -version