ubuntu13.04下安装jdk7

参考http://www.neversaydie.cc/ubuntu-install-jdk-in-detailed/而来


1.手工从Oralce官网下载jdk-7u25-linux-x64.gz然后mvjdk-7u25-linux-x64.gz/usr/local/devtools


2.解压tarzxvfjdk-7u25-linux-x64.gz


3.设置环境变量

vim/etc/profile

按a进入编辑模式,在文件最后输入

#set java environment

  1. exportJAVA_HOME=/usr/local/devtools/jdk1.7.0_25
  2. exportCLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
  3. exportPATH=${JAVA_HOME}/bin:$PATH
  4. 按ESC退出编辑模式,输入:wq

PS:看到有好多人设置了JRE_HOME,个人认为没有必要

使命令生效
source/etc/profile

4.再次设置环境变量
vim/etc/bash.bashrc

按a进入编辑模式,在文件最后输入

#set java environment

  1. exportJAVA_HOME=/usr/local/devtools/jdk1.7.0_25
  2. exportCLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
  3. exportPATH=${JAVA_HOME}/bin:$PATH
  4. 按ESC退出编辑模式,输入:wq

使命令生效
source/etc/bash.bashrc

5.如果ubuntu可能还会有默认的jdk,如openjdk;为了使默认使用的是我们安装的jdk,还需执行如下命令:
  1. sudoupdate-alternatives--install/usr/bin/javajava/usr/local/devtools/jdk1.7.0_25/bin/java300
  2. sudoupdate-alternatives--install/usr/bin/javacjavac/usr/local/devtools/jdk1.7.0_25/bin/javac300
  3. sudoupdate-alternatives--install/usr/bin/jarjar/usr/local/devtools/jdk1.7.0_25/bin/jar300
  4. sudoupdate-alternatives--install/usr/bin/javahjavah/usr/local/devtools/jdk1.7.0_25/bin/javah300
  5. sudoupdate-alternatives--install/usr/bin/javapjavap/usr/local/devtools/jdk1.7.0_25/bin/javap300

sudoupdate-alternatives--configjava

6.验证安装是否成功
java -version
出现一下信息则说明成功了
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

你可能感兴趣的:(ubuntu)