CentOS7上以rpm方式安装JDK8
程序员文章站
2023-09-07 08:33:48
centos 7 安装成功后可能已经默认安装了openjdk的jre,但平时进行java开发时需要用完整的jdk,所以为了避免以后不必要的麻烦,在此卸载了openjdk的jre,并重新安装了oracl...
centos 7 安装成功后可能已经默认安装了openjdk的jre,但平时进行java开发时需要用完整的jdk,所以为了避免以后不必要的麻烦,在此卸载了openjdk的jre,并重新安装了oracle的jdk8
1.安装说明
系统环境:centos 7
安装方式:rpm
安装包:
2.检查系统原安装版本
[hadoop@centos7-1 ~]$ java -version openjdk version "1.8.0_131" openjdk runtime environment (build 1.8.0_131-b12) openjdk 64-bit server vm (build 25.131-b12, mixed mode)
[hadoop@centos7-1 ~]$ rpm -qa|grep java libvirt-java-devel-0.4.9-4.el7.noarch tzdata-java-2017b-1.el7.noarch java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64 java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64 libvirt-java-0.4.9-4.el7.noarch javapackages-tools-3.4.1-11.el7.noarch java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64 java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64 python-javapackages-3.4.1-11.el7.noarch [hadoop@centos7-1 ~]$
3.卸载系统已安装的openjdk
libvirt-java-devel-0.4.9-4.el7.noarch libvirt-java-0.4.9-4.el7.noarch tzdata-java-2017b-1.el7.noarch java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64 java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64 java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64 java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
以root身份运行以下命令
[root@centos7-1 hadoop]# rpm -e --nodeps libvirt-java-devel-0.4.9-4.el7.noarch [root@centos7-1 hadoop]# rpm -e --nodeps libvirt-java-0.4.9-4.el7.noarch [root@centos7-1 hadoop]# rpm -e --nodeps tzdata-java-2017b-1.el7.noarch [root@centos7-1 hadoop]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64 [root@centos7-1 hadoop]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64 [root@centos7-1 hadoop]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.131-3.b12.el7_3.x86_64 [root@centos7-1 hadoop]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64
4.安装jdk
[root@centos7-1 local]# ll /usr/local/jdk-8u131-linux-x64.rpm -rw-r--r--. 1 root root 169983496 6月 12 23:17 /usr/local/jdk-8u131-linux-x64.rpm [root@centos7-1 local]# rpm -ivh jdk-8u131-linux-x64.rpm preparing... ################################# [100%] updating / installing... 1:jdk1.8.0_131-2000:1.8.0_131-fcs ################################# [100%] unpacking jar files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... [root@centos7-1 local]#
jdk默认安装到了 /usr/java/ 下面
[root@centos7-1 local]# ll /usr/java/ total 0 lrwxrwxrwx. 1 root root 16 6月 12 23:18 default -> /usr/java/latest drwxr-xr-x. 9 root root 268 6月 12 23:18 jdk1.8.0_131 lrwxrwxrwx. 1 root root 22 6月 12 23:18 latest -> /usr/java/jdk1.8.0_131 [root@centos7-1 local]#
5.验证安装
[root@centos7-1 local]# ll /usr/bin/java lrwxrwxrwx. 1 root root 22 6月 12 23:18 /usr/bin/java -> /etc/alternatives/java [root@centos7-1 local]# ll /etc/alternatives/java lrwxrwxrwx. 1 root root 35 6月 12 23:18 /etc/alternatives/java -> /usr/java/jdk1.8.0_131/jre/bin/java [root@centos7-1 local]# java -version java version "1.8.0_131" java(tm) se runtime environment (build 1.8.0_131-b11) java hotspot(tm) 64-bit server vm (build 25.131-b11, mixed mode) [root@centos7-1 local]#
6.配置环境变量
[hadoop@centos7-1 ~]$ whoami hadoop [hadoop@centos7-1 ~]$ vi ~/.bashrc
设置java_home,并将它加到path中
java_home=/usr/java/default path=$path:$java_home/bin export java_home path
运行source命令,使修改生效。输出java_home, path确认修改是否生效。
[hadoop@centos7-1 ~]$ source ~/.bashrc [hadoop@centos7-1 ~]$ echo $java_home /usr/java/default [hadoop@centos7-1 ~]$ echo $path /usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/hadoop/.local/bin:/home/hadoop/bin:/usr/java/default/bin
至此,centos 7上安装jdk8顺利完毕,更多关于linux下安装jdk的文章请查看下面相关链接
推荐阅读
-
centos7上编译安装php7以php-fpm方式连接apache
-
centos7上mysql8.0rpm方式安装教程图解
-
CentOS7上以rpm方式安装JDK8
-
OL7.6上RPM方式安装Oracle 19c
-
centos7上mysql8.0rpm方式安装
-
Linux系统下以RPM方式如何安装mysql-5.7.9
-
OL7.6上RPM方式安装Oracle 19c的教程
-
在CentOS7上安装MySQL5.7-源码包方式
-
centos7用rpm安装mysql5.7【初始用yum安装发现下载非常慢,就考虑本地用迅雷下载rpm方式安装】
-
在CentOS上以源码编译的方式安装Greenplum数据库