因为项目需要, 所以要在机器上安装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 是不想影响全局系统环境变量)
加入下面的内容然后保存下.
<pre name="code" class="python">export JAVA_HOME=/usr/java/java7 export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar export PATH=$PATH:$JAVA_HOME/bin
接着
#source /root/.bashrc 切到你的用户下再source下即可. #echo $JAVA_HOME /usr/java/java7
#/usr/java/java7/bin/java -version
#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
#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)