CentOS8安装更换JDK

2024-04-16 05:44
文章标签 jdk 安装 更换 centos8

本文主要是介绍CentOS8安装更换JDK,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

CentOS8安装更换JDK

背景:在服务器上启动java项目报错,JDK问题。更换jdk。探索整理安装JDK的方法。一些常用系统命令。清华源下载。

文章目录

  • CentOS8安装更换JDK
    • 准备工作:查看本地相关信息
  • 方式一:yum安装
    • 搜索
    • 安装
    • 配置环境变量
  • 方式二:官网下载压缩包安装
    • 获取下载链接(官网或者[国内镜像清华](https://mirrors.tuna.tsinghua.edu.cn/Adoptium/) )
    • 解压(即安装)
    • 配置环境变量

准备工作:查看本地相关信息

#查看系统的硬件架构
(base) [root@Server ~]# uname -m
x86_64(base) [root@Servere ~]# uname -a
Linux Server-3401572e-0499-44a9-88bb-b2b2061f3c4e 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
(base) [root@Server ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="8"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="8"
PLATFORM_ID="platform:el8"
PRETTY_NAME="CentOS Linux 8"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:8"
HOME_URL="https://centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
(base) [root@Server ~]# lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              16
On-line CPU(s) list: 0-15
Thread(s) per core:  2
Core(s) per socket:  8
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
BIOS Vendor ID:      QEMU
CPU family:          6
Model:               85
Model name:          Intel(R) Xeon(R) Gold 6161 CPU @ 2.20GHz
BIOS Model name:     pc-i440fx-2.8
Stepping:            4
CPU MHz:             2200.000
BogoMIPS:            4400.00
Hypervisor vendor:   KVM
Virtualization type: full
L1d cache:           32K
L1i cache:           32K
L2 cache:            1024K
L3 cache:            30976K
NUMA node0 CPU(s):   0-15
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 arat md_clear flush_l1d#查看当前jdk版本
(base) [root@Server ~]# java --version
openjdk 17.0.8 2023-07-18
OpenJDK Runtime Environment GraalVM CE 22.3.3 (build 17.0.8+7-jvmci-22.3-b22)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.3 (build 17.0.8+7-jvmci-22.3-b22, mixed mode, sharing)#查看当前系统安装了哪些关于java的东西
(base) [root@Server ~]# rpm -qa | grep java
javapackages-filesystem-5.3.0-1.module_el8.0.0+11+5b8c10bd.noarch
java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64
java-11-openjdk-headless-11.0.13.0.8-4.el8_5.x86_64
tzdata-java-2021e-1.el8.noarch(base) [root@Server ~]# rpm -qa | grep jdk
java-11-openjdk-11.0.13.0.8-4.el8_5.x86_64
java-11-openjdk-headless-11.0.13.0.8-4.el8_5.x86_64
copy-jdk-configs-4.0-2.el8.noarch(base) [root@Server ~]# yum list installed | grep java
java-11-openjdk.x86_64                             1:11.0.13.0.8-4.el8_5                         @appstream
java-11-openjdk-headless.x86_64                    1:11.0.13.0.8-4.el8_5                         @appstream
javapackages-filesystem.noarch                     5.3.0-1.module_el8.0.0+11+5b8c10bd            @appstream
tzdata-java.noarch                                 2021e-1.el8                                   @appstream

java配置环境变量可参考博客了解配置这些到底是干啥用的

(base) [root@Server ~]# vim ~/.bash_profile
#配置环境变量
#Java
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk/jdk-17.0.10+7  # JDK 17安装路径
export PATH=$JAVA_HOME/bin:$PATH

方式一:yum安装

分三步:搜索,安装,配置环境变量

优点:直接install就完事了!

缺点:版本较少,没办法满足需求!

搜索

(base) [root@Server ~]# yum search java | grep -i --color JDK
Last metadata expiration check: 3:00:04 ago on Mon 15 Apr 2024 12:39:17 PM CST.
......
java-17-openjdk.x86_64 : OpenJDK 17 Runtime Environment
java-17-openjdk-demo.x86_64 : OpenJDK 17 Demos
java-17-openjdk-devel.x86_64 : OpenJDK 17 Development Environment
java-17-openjdk-headless.x86_64 : OpenJDK 17 Headless Runtime Environment
java-17-openjdk-javadoc.x86_64 : OpenJDK 17 API documentation
java-17-openjdk-javadoc-zip.x86_64 : OpenJDK 17 API documentation compressed in a single archive
java-17-openjdk-jmods.x86_64 : JMods for OpenJDK 17
......
icedtea-web.x86_64 : Additional Java components for OpenJDK - Java browser plug-in and Web Start implementation
openjdk-asmtools.noarch : Set of tools used to assemble / disassemble proper and improper Java .class files
openjdk-asmtools7.noarch : Set of tools used to assemble / disassemble proper and improper Java .class files for JDK version 11 and lesser

安装

(base) [root@Server ~]# yum install java-17-openjdk.x86_64
Last metadata expiration check: 3:00:49 ago on Mon 15 Apr 2024 12:39:17 PM CST.
Dependencies resolved.
======================================================================================================================Package                             Architecture      Version                             Repository            Size
======================================================================================================================
Installing:java-17-openjdk                     x86_64            1:17.0.1.0.12-2.el8_5               appstream            244 k
Installing dependencies:java-17-openjdk-headless            x86_64            1:17.0.1.0.12-2.el8_5               appstream             41 MTransaction Summary
======================================================================================================================
Install  2 PackagesTotal download size: 41 M
Installed size: 190 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): java-17-openjdk-17.0.1.0.12-2.el8_5.x86_64.rpm                                 146 kB/s | 244 kB     00:01
(2/2): java-17-openjdk-headless-17.0.1.0.12-2.el8_5.x86_64.rpm                        8.7 MB/s |  41 MB     00:04
----------------------------------------------------------------------------------------------------------------------
Total                                                                                 8.7 MB/s |  41 MB     00:04
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionRunning scriptlet: java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64                                        1/1Preparing        :                                                                                              1/1Installing       : java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64                                        1/2Running scriptlet: java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64                                        1/2Installing       : java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64                                                 2/2Running scriptlet: java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64                                                 2/2Verifying        : java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64                                                 1/2Verifying        : java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64                                        2/2Installed:java-17-openjdk-1:17.0.1.0.12-2.el8_5.x86_64          java-17-openjdk-headless-1:17.0.1.0.12-2.el8_5.x86_64Complete!

配置环境变量

同最上面(vim时注意目录)yum安装默认目录为 /usr/lib/jvm

方式二:官网下载压缩包安装

获取下载链接(官网或者国内镜像清华 )

(base) [root@Server env]# wget https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jdk/x64/linux/OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz
--2024-04-15 16:25:37--  https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jdk/x64/linux/OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130, 2402:f000:1:400::2
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 192205930 (183M) [application/octet-stream]
Saving to: ‘OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz’OpenJDK17U-jdk_x64_linux_hots 100%[=================================================>] 183.30M  11.4MB/s    in 18s2024-04-15 16:25:55 (10.5 MB/s) - ‘OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz’ saved [192205930/192205930]

解压(即安装)

#报错
(base) [root@Server env]# sudo tar -xzvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz /usr/lib/jvm/java-17-openjdk
tar: /usr/lib/jvm/java-17-openjdk: Not found in archive
tar: Exiting with failure status due to previous errors
#以为是没创建目录
(base) [root@Server env]# mkdir /usr/lib/jvm/java-17-openjdk
#根本原因没有指定 -C 即解压目录
(base) [root@Server env]# sudo tar -xzvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz /usr/lib/jvm/java-17-openjdk
tar: /usr/lib/jvm/java-17-openjdk: Not found in archive
tar: Exiting with failure status due to previous errors
(base) [root@Server env]# sudo tar -xzvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.10_7.tar.gz -C /usr/lib/jvm/java-17-openjdk
jdk-17.0.10+7/
jdk-17.0.10+7/bin/
jdk-17.0.10+7/bin/javap
jdk-17.0.10+7/bin/jar
...
....
jdk-17.0.10+7/conf/logging.properties

配置环境变量

(base) [root@Server env]# vim ~/.bash_profile
(base) [root@Server env]# source ~/.bash_profile
(base) [root@Server env]# java -version
openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment Temurin-17.0.10+7 (build 17.0.10+7)
OpenJDK 64-Bit Server VM Temurin-17.0.10+7 (build 17.0.10+7, mixed mode, sharing)

这篇关于CentOS8安装更换JDK的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907932

相关文章

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

MySQL Workbench 安装教程(保姆级)

《MySQLWorkbench安装教程(保姆级)》MySQLWorkbench是一款强大的数据库设计和管理工具,本文主要介绍了MySQLWorkbench安装教程,文中通过图文介绍的非常详细,对大... 目录前言:详细步骤:一、检查安装的数据库版本二、在官网下载对应的mysql Workbench版本,要是

Linux安装MySQL的教程

《Linux安装MySQL的教程》:本文主要介绍Linux安装MySQL的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux安装mysql1.Mysql官网2.我的存放路径3.解压mysql文件到当前目录4.重命名一下5.创建mysql用户组和用户并修

pip无法安装osgeo失败的问题解决

《pip无法安装osgeo失败的问题解决》本文主要介绍了pip无法安装osgeo失败的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 进入官方提供的扩展包下载网站寻找版本适配的whl文件注意:要选择cp(python版本)和你py

JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)

《JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)》本文介绍了如何在Windows系统上配置多版本JDK(以JDK8和JDK17为例),并通过图文结合的方式给大家讲解了详细步骤,具有... 目录第一步 下载安装JDK第二步 配置环境变量第三步 切换JDK版本并验证可能遇到的问题前提:公司常

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

Python解析器安装指南分享(Mac/Windows/Linux)

《Python解析器安装指南分享(Mac/Windows/Linux)》:本文主要介绍Python解析器安装指南(Mac/Windows/Linux),具有很好的参考价值,希望对大家有所帮助,如有... 目NMNkN录1js. 安装包下载1.1 python 下载官网2.核心安装方式3. MACOS 系统安

Pycharm安装报错:Cannot detect a launch configuration解决办法

《Pycharm安装报错:Cannotdetectalaunchconfiguration解决办法》本文主要介绍了Pycharm安装报错:Cannotdetectalaunchconfigur... 本文主要介绍了Pycharm安装报错:Cannot detect a launch configuratio

pytorch+torchvision+python版本对应及环境安装

《pytorch+torchvision+python版本对应及环境安装》本文主要介绍了pytorch+torchvision+python版本对应及环境安装,安装过程中需要注意Numpy版本的降级,... 目录一、版本对应二、安装命令(pip)1. 版本2. 安装全过程3. 命令相关解释参考文章一、版本对

Windows系统下如何查找JDK的安装路径

《Windows系统下如何查找JDK的安装路径》:本文主要介绍Windows系统下如何查找JDK的安装路径,文中介绍了三种方法,分别是通过命令行检查、使用verbose选项查找jre目录、以及查看... 目录一、确认是否安装了JDK二、查找路径三、另外一种方式如果很久之前安装了JDK,或者在别人的电脑上,想