下载JDK
jre-7u75-linux-x64.tar.gz,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
解压JDK包
tar -zxvf jre-7u75-linux-x64.tar.gz
mv jre1.7.0_75 /usr/java/
完成后配置JAVA环境变量
vim /root/.bash_profile
增加如下环境变量:
JAVA_HOME=/usr/java/jre1.7.0_75
export JRE_HOME=/usr/java/jre1.7.0_75
export PATH=$PATH:/usr/java/jre1.7.0_75/bin
export CLASSPATH=./:/usr/java/jre1.7.0_75/lib
export JAVA_HOME
然后生效配置文件
source /root/.bash_profile
正常情况下是可以java -version查看当前java版本了。如果系统之前有JDK的话,那还要执行一下命令
sudo update-alternatives --install /usr/bin/java java /usr/java/jre1.7.0_75/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/java/jre1.7.0_75/javac 300
sudo update-alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/java/jre1.7.0_75/bin/java
Enter to keep the current selection[+],or type selection number: 1
java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04,mixed mode)
这样JDK就安装好了。
原文链接:https://www.f2er.com/centos/380019.html