Debian(Wheezy)安装Java环境/替换OpenJDK为SUN JDK
因为项目需要, 所以要在机器上安装Java环境.
1, 去http://www.Oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 下载, 选择了Accept License Agreement
选择了linux x64的jdk-7u71-linux-x64.tar.gz
2, #接下来找个目录来放sun JDK, 这里我们放到/usr/java, 并且以数字来表明版本,比如java8 就在/usr/java/java8, java7就在/usr/java/java7
创建/usr/java 目录, 然后解压压缩包, 移到/usr/java/java7
#mkdir /usr/java && tar -zxvf jdk-7u71-linux-x64.tar.gz && mv jdk1.7.0_71 /usr/java/java7
3,写java的环境变量
用编辑器打开你的.bashrc文件. 这个有两个, 一个在/root/.bashrc ,一个在/home/你的username/.bashrc (不写/etc/environment 是不想影响全局系统环境变量)
加入下面的内容然后保存下.
export JAVA_HOME=/usr/java/java7
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
接着
#source /root/.bashrc 切到你的用户下再source下即可.
#echo $JAVA_HOME
/usr/java/java7
对于没有安装过openjdk的, 这时在终端直接输入
#/usr/java/java7/bin/java -version
这时我们开始作链接.加入到系统的bin, 用update-alternatives命令来维护系统的软连接,通过更新这个来让系统知道用哪个命令. 最后一个参数是优先级.越高越好.
#update-alternatives –install /usr/bin/java java /usr/java/java7/bin/java 1100
#update-alternatives –install /usr/bin/javac javac /usr/java/java7/bin/javac 1100
接下来配置, 如果你安装了openJDK的, 这里就可以选了. 因为前面我给了一个更高的优先级1100, 所以现在默认的已经是/usr/java/java7 下的了.
#update-alternatives –config java
#update-alternatives –config javac
root@debian:/# update-alternatives –config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
————————————————————
0 /usr/java/java7/bin/java 1100 auto mode
* 1 /usr/java/java7/bin/java 1100 manual mode
2 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
root@debian:/# update-alternatives –config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
————————————————————
* 0 /usr/java/java7/bin/javac 1100 auto mode
1 /usr/java/java7/bin/javac 1100 manual mode
2 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
然后直接在终端输入验证下java7是否安装ok
#java -version
java version “1.7.0_71”
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
Linux(CentOS)下配置安装Tomcat并配置JDK环境 http://www.linuxidc.com/Linux/2013-11/93286.htm
Ubuntu14.04 64位 安装JDK1.7 http://www.linuxidc.com/Linux/2015-01/111102.htm
Ubuntu下安装JDK7(附Clojure下载) http://www.linuxidc.com/Linux/2012-10/71557.htm
Ubuntu 12.04下安装JDK1.7 http://www.linuxidc.com/Linux/2012-06/62239.htm
CentOS6.3安装JDK和环境配置 http://www.linuxidc.com/Linux/2012-09/70780.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111177.htm