安装OpenJDK1.8 :
检查当前机器是否有自带的JDK:
1
2
3
|
rpm -qa |grep java
rpm -qa |grep jdk
rpm -qa |grep gcj
|
如果没有 则跳至安装步骤,有的话 进行卸载:
1
|
rpm -qa | grep java | xargs rpm -e --nodeps
|
更新yum源:
1
|
yum update -y
|
搜索yum中的软件包:
1
|
yum list java-1.8*
|
安装OpenJDK:
1
|
yum install java-1.8.0-openjdk* -y
|
验证是否安装成功:
1
2
3
4
5
|
java -version
返回信息如下,则说明安装成功:
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
|
其它常见问题:
如果出现command not found
命令找不到的话,则说明环境除了问题,此时需要找到OpenJDK的安装位置,将其配置到/etc/profile
文件中:
1
2
3
4
|
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-3.b14.el6_9.x86_64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=$CLASSPATH:.:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib
export PATH=${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH
|
配置完成之后,重新加载一下该文件:
1
|
source /etc/profile
|
安装OracleJDK1.8 :
下载 OracleJDK1.8 & 上传:
1
2
|
下载地址:
http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz
|
1
2
3
|
➜ Linux Soft scp jdk-8u171-linux-x64.tar.gz root@192.168.1.10:/opt
root@192.168.1.10's password:
jdk-8u171-linux-x64.tar.gz
|
解压至/usr/
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@centos-linux ~]# cd /opt/
[root@centos-linux opt]# du -sm jdk-8u171-linux-x64.tar.gz
183 jdk-8u171-linux-x64.tar.gz
[root@centos-linux opt]# tar -xf jdk-8u171-linux-x64.tar.gz
[root@centos-linux opt]# mv jdk
jdk1.8.0_171/ jdk-8u171-linux-x64.tar.gz
[root@centos-linux opt]# mv jdk1.8.0_171 jdk
jdk1.8.0_171/ jdk-8u171-linux-x64.tar.gz
[root@centos-linux opt]# mv jdk1.8.0_171 jdk1.8
[root@centos-linux opt]# mv jdk1.8/ /usr/
[root@centos-linux opt]# cd /usr/
[root@centos-linux usr]# ls
bin etc games include jdk1.8 lib lib64 libexec local sbin share src tmp
[root@centos-linux usr]# cd jdk1.8/
[root@centos-linux jdk1.8]# pwd
/usr/jdk1.8
|
配置环境变量:
1
2
3
4
5
6
7
8
9
10
11
|
[root@centos-linux ~]# vim /etc/profile
export JAVA_HOME=/usr/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=$CLASSPATH:.:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib
export PATH=${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin:$PATH
[root@centos-linux ~]# source /etc/profile
|
验证是否安装成功:
1
2
3
4
|
[root@centos-linux ~]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
|