Linux环境JDK安装

时间:2022-03-21 18:19:09

Java的编程离不开jdk,今天本文主要讲下Linux下的JDK安装与配置

1、卸载Linux自带的JDK

 

#检测jdk安装包
[root@localhost
~]# rpm -qa | grep java
java
-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java
-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64

#卸载linux自带的openjdk
[root@localhost
~] yum -y remove java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64

[root@localhost
~] yum -y remove java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64

# 再次输入rpm
-qa | grep java 查看卸载情况
[root@localhost
~]# rpm -qa | grep java

 

 

 

2、JDK下载安装

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

点击链接后,你应该看到如下图所示界面:

Linux环境JDK安装

点击接受许可协议,选择红框标记的jdk进行下载.

将下载后的JDK通过xftp上传到/usr/local/jdk目录下,进入该目录,给安装包赋予运行权限

#安装包赋权限
chmod
755 jdk-8u161-linux-x64.rpm

安装:

rpm –i jdk-8u161-linux-x64.rpm

等待安装完成以后,接下来我们设置环境变量

2、JDK环境变量配置

[root@localhost ~]# vim /etc/profile

#在文件末位添加如下配置
JAVA_HOME
=/usr/java/jdk1.8.0_161
PATH
=$JAVA_HOME/bin:$PATH
CLASSPATH
=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

测试jdk是否安装成功

[root@localhost ~]# java -version