jdk 21 install linux(centos 9 stream)

本文指导如何在RPM系统(如RedHat和SuSE)上使用下载的.rpm文件安装64位JDK,包括下载对应版本的RPM包,使用`sudorpm-ivh`安装或升级,以及JDK版本管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、RPM方式在linux上进行安装:

参考orcal官网的文章
linux配置环境命令的检测就是从其他目录下执行对应的java javac 等命令可以执行就行
yum安装,安装的软件会自动把环境变量配置好

Installing the 64-Bit JDK on RPM-Based Linux Platforms
You can install the JDK on 64-bit RPM-based Linux platforms, such as Red Hat and SuSE by using a downloadable RPM package file (.rpm) in the system location.

Note:You can install the JDK using a downloadable RPM package file on an OL system too, but the preferred way to install the JDK on OL systems is from Oracle Linux RPM repositories.
Ensure that you have the root user access. You can do this by running the command su and entering the superuser password.
To install the 64-bit JDK on an RPM-based Linux platform:
Download the required file:
For x64 systems: jdk-21.interim.update.patch_linux-x64_bin.rpm. For example, jdk-21_linux-x64_bin.rpm
For aarch64 (64-bit ARM) systems: jdk-21.interim.update.patch_linux-aarch64_bin.rpm. For example, jdk-21_linux-aarch64_bin.rpm
Before you download a file, you must accept the license agreement.

Install the required package using the following command:
$ sudo rpm -ivh jdk-21_linux-x64_bin.rpm

OR

$ sudo rpm -ivh jdk-21_linux-aarch64_bin.rpm

Upgrade the required package using the following command:

$ sudo rpm -Uvh jdk-21_linux-x64_bin.rpm

OR

$ sudo rpm -Uvh jdk-21_linux-aarch64_bin.rpm

Note:JDK 21 can coexist with other feature releases of JDK. For each feature release, a separate directory is created, the default directory being /usr/lib/jvm/jdk--oracle-. For example, JDK 21 releases for x64 will be installed in /usr/lib/jvm/jdk-21-oracle-x64 directory.
Delete the .rpm file if you want to save disk space.
It is not required to reboot.

orcal site description(beautiful layout)
awsome layout !!!

2、使用yum安装的软件一些特点

  • 使用yum安装会采用linux下目录的特性
    example: 例如nginx升级,如果采用yum安装方式安装后
a.目录分层很清楚
[root@iZuf6chlqotgoe8s0enis8Z ~]# find / -name nginx
/root/dev_workspace/nginx_upgrade/nginx-1.26.2/objs/nginx
/root/dev_workspace/nginx_upgrade/nginx-1.4.7/objs/nginx
/var/log/nginx
/var/cache/nginx
/var/lib/nginx
/usr/share/nginx
/usr/lib64/nginx
/usr/sbin/nginx
/etc/nginx

b.会加很多参数,比使用rpm包管理安装的更多参数
[root@iZuf6chlqotgoe8s0enis8Z ~]# nginx -V
nginx version: nginx/1.26.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'


对比一般自己安装的nginx 
configure arguments: --prefix=/usr/local/nginx
一般自己安装的路径后期升级按照源码编译时比较好找位置


c.卸载软件
以java为例
[root@iZuf6chlqotgoe8s0enis8Z ~]# yum list installed |grep java
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.412.b08-1.el7_9          @updates    
java-11-openjdk-headless.x86_64    1:11.0.23.0.9-2.el7_9            @updates    
javapackages-tools.noarch          3.4.1-11.el7                     @base       
python-javapackages.noarch         3.4.1-11.el7                     @base       
tzdata-java.noarch                 2024a-1.el7                      @updates 

[root@iZuf6chlqotgoe8s0enis8Z ~]# yum remove java-1.8.0-openjdk-headless.x86_64

使用压缩包安装

下载对应架构的包 https://www.oracle.com/java/technologies/downloads/archive/
tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/java8

vim /etc/profile
#追加java的环境变量
export JAVA_HOME=/usr/local/java8
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin
配置对应的环境变量
source /etc/profile



一些参考
1、在Linux上安装Java(2021):https://www.cnblogs.com/zhuangjie/p/14868347.html

期间的一些变动
1、阅读了部分的《鸟哥的linux的私房菜》

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值