下载java的rpm安装包
去官网直接下载即可,下载地址下载
国内下载地址:https://www.injdk.cn/
检验系统原版本
[root@localhost ~]# java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.3.el7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
[root@localhost ~]# ls
进一步查看JDK信息:
[root@localhost ~]# rpm -qa | grep java
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
tzdata-java-2015g-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
卸载OpenJDK,执行以下操作:
[root@localhost ~]# rpm -e --nodeps tzdata-java-2015g-1.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
[root@localhost ~]# rpm -e --nodeps javapackages-tools-3.4.1-11.el7.noarch
安装rpm包
mkdir /usr/java
cp jdk-8u91-linux-x64.rpm /usr/java/jdk-8u91-linux-x64.rpm
chmod +x jdk-8u91-linux-x64.rpm
rpm -ivh jdk-8u91-linux-x64.rpm
配置环境变量
命名行模式
echo "########################" >> /etc/profile
echo "# For user_add_jdk start" >> /etc/profile
echo "JAVA_HOME=/usr/java/jdk1.8.0_91" >> /etc/profile
echo "JRE_HOME=/usr/java/jdk1.8.0_91/jre" >> /etc/profile
echo "PATH=\$PATH:\$JAVA_HOME/bin:\$JRE_HOME/bin" >> /etc/profile
echo "CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib" >> /etc/profile
echo "export JAVA_HOME JRE_HOME PATH CLASSPATH" >> /etc/profile
echo "# For user_add_jdk end " >> /etc/profile
echo "########################" >> /etc/profile
编辑配置
终端输入vim /etc/profile
在末尾追加如下内容
# For user_add_jdk start
JAVA_HOME=/usr/java/jdk1.8.0_91
JRE_HOME=/usr/java/jdk1.8.0_91/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib"
export JAVA_HOME JRE_HOME PATH CLASSPATH
# For user_add_jdk end
推荐配置
vim ~/.bash_profile
PATH=$PATH:$HOME/bin
########################
# For user_add_jdk start
JAVA_HOME=/usr/java/jdk1.8.0_91
JRE_HOME=/usr/java/jdk1.8.0_91/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
# For user_add_jdk end
########################
export PATH
~
windows环境变量配置
CLASSPATH
.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
JAVA_HOME
D:\Program Files\Java\jdk1.8.0_25
M2_HOME
E:\maven\apache-maven-3.3.9
PATH
%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;%M2_HOME%\bin;
安装成功
[root@localhost ~]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
[root@localhost ~]#