yum安装配置jdk
程序员文章站
2022-06-21 13:42:16
1、检查是否已安装JDK及卸载以下命令二选一,中括号选一即可yum list installed | grep [java][jdk]rpm -qa | grep [java][jdk][gcj][root@localhost ~]# yum list installed | grep javaRepodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fastjava-1.7.0-openjdk.x86_64...
1、检查是否已安装JDK及卸载
以下命令二选一,中括号选一即可
yum list installed | grep [java][jdk]
rpm -qa | grep [java][jdk][gcj]
[root@localhost ~]# yum list installed | grep java
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
java-1.7.0-openjdk.x86_64 1:1.7.0.111-2.6.7.8.el7 @anaconda
java-1.7.0-openjdk-headless.x86_64 1:1.7.0.111-2.6.7.8.el7 @anaconda
java-1.8.0-openjdk.x86_64 1:1.8.0.102-4.b14.el7 @anaconda
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.102-4.b14.el7 @anaconda
javapackages-tools.noarch 3.4.1-11.el7 @anaconda
python-javapackages.noarch 3.4.1-11.el7 @anaconda
tzdata-java.noarch 2016g-2.el7 @anaconda
执行命令出现如上图所示,需要卸载,反之即不用
卸载JAVA环境:
yum -y remove java-1.6.0-openjdk* //表时卸载所有openjdk相关文件输入
yum -y remove tzdata-java.noarch //卸载tzdata-java
2、安装JDK
查看JDK软件包列表
yum search java | grep -i --color jdk
选择版本安装
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
#或如下命令,安装jdk1.8.0的所有文件
yum install -y java-1.8.0-openjdk*
查看JDK是否安装成功
[root@localhost ~]# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
3、配置环境变量
JDK默认安装路径/usr/lib/jvm
[root@localhost ~]# ls /usr/lib/jvm
java java-openjdk jre-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
java-1.8.0 jre jre-openjdk
java-1.8.0-openjdk jre-1.8.0
java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64 jre-1.8.0-openjdk
在/etc/profile文件添加如下命令
[root@localhost ~]# vim /etc/profile
# set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
保存关闭profile文件,执行如下命令生效
[root@localhost ~]# source /etc/profile
使用如下命令,查看JDK变量
echo $JAVA_HOME
echo $PATH
echo $CLASSPATH
[root@localhost ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64
[root@localhost ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/bin
[root@localhost ~]# echo $CLASSPATH
.:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/lib/dt.jar:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/lib/tools.jar
本文地址:https://blog.csdn.net/weixin_45373345/article/details/107699566