1.手工从Oralce官网下载jdk-7u25-linux-x64.gz 然后mv jdk-7u25-linux-x64.gz /usr/local/devtools
2.解压 tar zxvf jdk-7u25-linux-x64.gz
3.设置环境变量
vim
/etc/profile
按a进入编辑模式,在文件最后输入
#set java environment
- export JAVA_HOME=/usr/local/devtools/jdk1.7.0_25
- export CLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
- export PATH=${JAVA_HOME}/bin:$PATH
- 按ESC退出编辑模式,输入:wq
PS:看到有好多人设置了JRE_HOME,个人认为没有必要
使
命令生效source
/etc/profile
4.再次设置环境变量
vim
/etc/bash
.bashrc
按a进入编辑模式,在文件最后输入
#set java environment
- export JAVA_HOME=/usr/local/devtools/jdk1.7.0_25
- export CLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
- export PATH=${JAVA_HOME}/bin:$PATH
- 按ESC退出编辑模式,输入:wq
使
命令生效source
/etc/bash
.bashrc
5.如果ubuntu可能还会有默认的jdk,如openjdk;为了使默认使用的是我们安装的jdk,还需执行如下命令:
- sudo update-alternatives --install /usr/bin/java java /usr/local/devtools/jdk1.7.0_25/bin/java 300
- sudo update-alternatives --install /usr/bin/javac javac /usr/local/devtools/jdk1.7.0_25/bin/javac 300
- sudo update-alternatives --install /usr/bin/jar jar /usr/local/devtools/jdk1.7.0_25/bin/jar 300
- sudo update-alternatives --install /usr/bin/javah javah /usr/local/devtools/jdk1.7.0_25/bin/javah 300
- sudo update-alternatives --install /usr/bin/javap javap /usr/local/devtools/jdk1.7.0_25/bin/javap 300
sudo update-alternatives --config java
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)
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)