ToB企服应用市场:ToB评测及商务社交产业平台

标题: 超详细!Linux上安装Java JDK21 环境! [打印本页]

作者: 南飓风    时间: 昨天 03:41
标题: 超详细!Linux上安装Java JDK21 环境!
在linux上安装Java环境 -JDK21

从官网上下载 JDK21-Linux版本

我们首先从官网上下载 linux JDK 的安装版本,下载地点:
JDK官方下载地点

JDK21 上传到虚拟机 Centos上

将下载好的 JDK21-Linux 版本 上传到我们的linux服务器上,比方你本地的虚拟机中安装的linux 环境
上传工具你可以使用 xshell 和 xftp; 你也可以使用 Mobaxterm;
下载Mobaxterm链接地点:
Mobaxterm官网下载地点



填写好虚拟机linux的ip地点,用户名,点击确定,会让你填写密码,填写完毕后即可毗连对应服务器
上传JDK21-Linux


将本地文件上传到对应的linux服务器上

创建JDK21解压目录并解压

首先切换到你下载的JDK目录下

创建jdk存放目录
  1. mkdir /usr/local/java
复制代码
将压缩包解压到上述目录当中
  1. tar -zxvf jdk-21_linux-64_bin.tar.gz -C /usr/local/java
复制代码
切换到 jdk 存放目录
  1. cd /usr/local/java
复制代码
查察结果如下,证明解压成功
  1. [root@localhost java]# ls jdk-21.0.5/
  2. bin  conf  include  jmods  legal  lib  LICENSE  man  README  release
复制代码
配置JAVA环境变量

创建软毗连

一般linux大概会有自己自带的java环境,是jdk1.8的,它已经占用了/usr/bin/java 的这个软链接
因此你必要先删除这个软毗连
  1. rm -rf /usr/bin/java
复制代码
然后重新创建 java 软链接到 /usr/bin/ 目录下
  1. ln -s /usr/local/java/jdk-21.0.5/ /usr/bin/java
复制代码
编辑体系配置文件

  1. vi /etc/profile
复制代码
按下 键盘 i 进入可编辑模式;按下shift + G 快速定位到文件末端处
然后输入以下内容
  1. export JAVA_HOME=/usr/bin/java
  2. export PATH=$JAVA_HOME/bin:$PATH
复制代码
输入完毕之后,按下 esc,进入到 不可编辑状态; 按下shift + :(shift + 冒号);此时在键盘输入字母 wq(wq表示保存退出的意思)
激活配置文件

  1. source /etc/profile
复制代码
验证java安装是否成功

  1. java --version
复制代码
若输出以下内容
  1. [root@localhost java]# java -version
  2. java version "21.0.5" 2024-10-15 LTS
  3. Java(TM) SE Runtime Environment (build 21.0.5+9-LTS-239)
  4. Java HotSpot(TM) 64-Bit Server VM (build 21.0.5+9-LTS-239, mixed mode, sharing)
复制代码
表示JDK21安装环境成功
可以输入 javac 再次举行验证
  1. [root@localhost java]# javac
  2. Usage: javac <options> <source files>
  3. where possible options include:
  4.   @<filename>                  Read options and filenames from file
  5.   -Akey[=value]                Options to pass to annotation processors
  6.   --add-modules <module>(,<module>)*
  7.         Root modules to resolve in addition to the initial modules,
  8.         or all modules on the module path if <module> is ALL-MODULE-PATH.
  9.   --boot-class-path <path>, -bootclasspath <path>
  10.         Override location of bootstrap class files
  11.   --class-path <path>, -classpath <path>, -cp <path>
  12.         Specify where to find user class files and annotation processors
  13.   -d <directory>               Specify where to place generated class files
  14.   -deprecation
  15.         Output source locations where deprecated APIs are used
  16.   --enable-preview
  17.         Enable preview language features.
  18.         To be used in conjunction with either -source or --release.
  19.   -encoding <encoding>         Specify character encoding used by source files
  20.   -endorseddirs <dirs>         Override location of endorsed standards path
  21.   -extdirs <dirs>              Override location of installed extensions
  22.   -g                           Generate all debugging info
  23.   -g:{lines,vars,source}       Generate only some debugging info
  24.   -g:none                      Generate no debugging info
  25.   -h <directory>
  26.         Specify where to place generated native header files
  27.   --help, -help, -?            Print this help message
  28.   --help-extra, -X             Print help on extra options
  29.   -implicit:{none,class}
  30.         Specify whether to generate class files for implicitly referenced files
  31.   -J<flag>                     Pass <flag> directly to the runtime system
  32.   --limit-modules <module>(,<module>)*
  33.         Limit the universe of observable modules
  34.   --module <module>(,<module>)*, -m <module>(,<module>)*
  35.         Compile only the specified module(s), check timestamps
  36.   --module-path <path>, -p <path>
  37.         Specify where to find application modules
  38.   --module-source-path <module-source-path>
  39.         Specify where to find input source files for multiple modules
  40.   --module-version <version>
  41.         Specify version of modules that are being compiled
  42.   -nowarn                      Generate no warnings
  43.   -parameters
  44.         Generate metadata for reflection on method parameters
  45.   -proc:{none,only,full}
  46.         Control whether annotation processing and/or compilation is done.
  47.   -processor <class1>[,<class2>,<class3>...]
  48.         Names of the annotation processors to run;
  49.         bypasses default discovery process
  50.   --processor-module-path <path>
  51.         Specify a module path where to find annotation processors
  52.   --processor-path <path>, -processorpath <path>
  53.         Specify where to find annotation processors
  54.   -profile <profile>
  55.         Check that API used is available in the specified profile.
  56.         This option is deprecated and may be removed in a future release.
  57.   --release <release>
  58.         Compile for the specified Java SE release.
  59.         Supported releases:
  60.             8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  61.   -s <directory>               Specify where to place generated source files
  62.   --source <release>, -source <release>
  63.         Provide source compatibility with the specified Java SE release.
  64.         Supported releases:
  65.             8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  66.   --source-path <path>, -sourcepath <path>
  67.         Specify where to find input source files
  68.   --system <jdk>|none          Override location of system modules
  69.   --target <release>, -target <release>
  70.         Generate class files suitable for the specified Java SE release.
  71.         Supported releases:
  72.             8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
  73.   --upgrade-module-path <path>
  74.         Override location of upgradeable modules
  75.   -verbose                     Output messages about what the compiler is doing
  76.   --version, -version          Version information
  77.   -Werror                      Terminate compilation if warnings occur
复制代码
以上就是 linux 虚拟机安装 JDK21的操纵过程
题外话:

免费建立了个测试群,免费分享一些资料,比方网课、面试题、简历模板等;






免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4