http://blog.csdn.net/viekie/article/details/7903203
第一步:下载jdk-7-linux-i586.tar.gz
- wget -c http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz
第二步:解压安装
- sudo tar zxvf ./jdk-7-linux-i586.tar.gz -C /usr/lib/jvm
- cd /usr/lib/jvm
- sudo mv jdk1.7.0/ java-7-sun
第三步:修改环境变量
- export JAVA_HOME=/usr/lib/jvm/java-7-sun
- export JRE_HOME=${JAVA_HOME}/jre
- export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
- export PATH=${JAVA_HOME}/bin:$PATH
第四步:配置默认JDK版本
由于ubuntu中可能会有默认的JDK,如openjdk,所以,为了将我们安装的JDK设置为默认JDK版本,还要进行如下工作。执行代码:
- sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
- sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300
- sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-sun/bin/jar 300
- sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java-7-sun/bin/javah 300
- sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java-7-sun/bin/javap 300
执行代码:
系统会列出各种JDK版本,如下所示:
第五步:测试
- snowdream@snowdream:~$ java -version
- java version "1.7.0"
- Java(TM) SE Runtime Environment (build 1.7.0-b147)
- Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
参考链接:
1、在Ubuntu 10.10下安装JDK配置Eclipse及Tomcat【转载 + 订正】 http://www.cnblogs.com/evasnowind/archive/2011/01/05/1926059.html
2、ubuntu安装jdk全过程(仅供参考) http://forum.ubuntu.org.cn/viewtopic.php?t=183803
3、java学习_jdk安装 http://www.cnblogs.com/shaoguobao/archive/2011/07/16/2108015.html