linux(centos7) 安装java-jdk
过程
1、卸载centos内置openjdk
2、下载jdk
3、安装jdk,配置系统路径
卸载centos内置openjdk
1、查看服务器是否安装openjdk
[root@localhost local]# rpm -qa|grep jdk
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
2、卸载所有已安装的openjdk,查出几个就卸载几次
[root@localhost local]# yum -y remove java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
[root@localhost local]# yum -y remove java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
[root@localhost local]# yum -y remove java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
[root@localhost local]# yum -y remove java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
3、确认是否完全卸载
[root@localhost local]# rpm -qa|grep jdk
[root@localhost local]# java -verson
-bash: /usr/bin/java: No such file or directory
下载jdk
推荐使用镜像下载,官网速度太慢
这是华为的镜像服务器:https://repo.huaweicloud.com/java/jdk/
版本自行选择,将下载的jdk上传到服务器目录
[root@localhost jdk-11.0.1]# pwd
/usr/local
安装jdk,配置系统路径
1、解压
[root@localhost local]# tar -zxvf jdk-11.0.1_linux-x64_bin.tar.gz
[root@localhost local]# ls
jdk-11.0.1 jdk-11.0.1_linux-x64_bin.tar.gz bin games lib
libexec share etc include lib64 sbin src
2、配置路径
[root@localhost local]# vi /etc/profile
在profile文件最后追加
export JAVA_HOME=/usr/local/jdk-11.0.1/
export JRE_HOME=/usr/local/jdk-11.0.1/jre
export PATH=$PATH:/usr/local/jdk-11.0.1/bin
export CLASSPATH=./:/usr/local/jdk-11.0.1/lib:/usr/local/jdk-11.0.1/jre/lib
保存退出:按 esc 输入:wq
:wq
重新编译配置文件,查看jdk版本,安装完成
[root@localhost local]# source /etc/profile
[root@localhost local]# java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)