centos是自带的openjdk,安装eclipse时, 下载最新的jdk。解压到/usr/java目录下。
tar zxvf jre-8u121-linux-x64.tar.gz
设置环境变量
#vi /etc/profile
export JAVA_HOME="/usr/java/jdk1.8.0_121"
export CLASS_PATH=".:/usr/java/jdk1.8.0_121/lib/dt.jar:/usr/java/jdk1.8.0_121/lib/tools.jar"
export PATH="$PATH:/usr/java/jdk1.8.0_121/bin"
#source /etc/profile
2 | [[email protected] ~] # alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_21/bin/java 400 |
3 | [[email protected] ~] # alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_21/bin/javac 400 |
现在可以看看注册的成果了:
03 | There are 3 programs which provide 'java' . |
06 | ----------------------------------------------- |
07 | *+ 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java |
08 | 2 /usr/java/jre1.6.0_21/bin/java |
09 | 3 /usr/java/jdk1.6.0_21/bin/java |
11 | Enter to keep the current selection[+], or type selection number: |
这里输入想要用的 java 就可以了,例如我选在了第2个。我们看看 /usr/bin/java的变化:
2 | lrwxrwxrwx 1 root root 22 Dec 17 2009 /usr/bin/java -> /etc/alternatives/java |
4 | lrwxrwxrwx 1 root root 30 Aug 23 15:03 /etc/alternatives/java -> /usr/java/jre |