ubuntu13安装jdk并配置环境变量

1.从Oralce官网下载jdk-7u45-linux-x64.gz 然后mv jdk-7u45-linux-x64.gz /usr/local/java
2.解压 tar -zxvf jdk-7u45-linux-x64.gz
3.设置环境变量
vim /etc/profile
按a进入编辑模式,在文件最后输入
#set java environment
export JAVA_HOME=/usr/local/java/jdk1.7.0_45  
export CLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
export PATH=${JAVA_HOME}/bin:$PATH
按ESC退出编辑模式,输入:wq

使命令生效
source /etc/profile

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

按a进入编辑模式,在文件最后输入
#set java environment
export JAVA_HOME=/usr/local/java/jdk1.7.0_45  
export CLASSPATH=.:${JAVA_HOME}/lib:$CLASSPATH
export PATH=${JAVA_HOME}/bin:$PATH
按ESC退出编辑模式,输入:wq

使命令生效
source /etc/bash.bashrc
(如果无权限,执行 chmod -774 /etc/bash.bashrc)

5.如果ubuntu可能还会有默认的jdk,如openjdk;为了使默认使用的是我们安装的jdk,还需执行如下命令:
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.7.0_45/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.7.0_45/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.7.0_45/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/local/java/jdk1.7.0_45/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/local/java/jdk1.7.0_45/bin/javap 300

sudo update-alternatives --config java

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

你可能感兴趣的:(Java)