Ubuntu 安装 Sun JDK

1. 下载
    Oracle网站下载JDK7
    根据机器的操作系统选择适合的版本,这里我们选择 jdk-7u75-linux-x64.tar.gz
2. 安装 
sudo mkdir /usr/lib/jvm
sudo tar zxvf ./jdk-7u75-linux-x64.tar.gz -C /usr/lib/jvm
cd /usr/lib/jvm
sudo mv jdk-7u75-linux-x64/ java-7-sun
3. 配置环境变量
    vi /etc/environment
    添加:    
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
    使配置文件生效:source /etc/environment

4. 配置默认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
    执行 sudo update-alternatives --config java 
5. 测试
    java -version 

posted on 2015-11-10 14:51  有点坏  阅读(1042)  评论(0编辑  收藏  举报

导航