centOS7 yum install java-1.8.0-openjdk

centOS7 yum install java-1.8.0-openjdk

执行安装命令

yum install java-1.8.0-openjdk
  • 安装成功后默认在 /usr/lib/jvm
[root@iZk0g7y0r8vpc5Z bin]# cd /usr/lib/jvm
[root@iZk0g7y0r8vpc5Z jvm]# pwd
/usr/lib/jvm
[root@iZk0g7y0r8vpc5Z jvm]# ll
total 4
lrwxrwxrwx 1 root root   26 May 16 00:05 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root   32 May 16 00:05 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
lrwxrwxrwx 1 root root   40 May 16 00:05 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk
drwxr-xr-x 7 root root 4096 May 16 00:05 java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
lrwxrwxrwx 1 root root   34 May 16 00:05 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root   21 May 15 23:01 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   27 May 15 23:01 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root   35 May 15 23:01 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx 1 root root   51 May 15 23:01 jre-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 -> java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre
lrwxrwxrwx 1 root root   29 May 15 23:01 jre-openjdk -> /etc/alternatives/jre_openjdk

  • 测试验证
[root@iZk0g7y0r8vpc5Z jvm]# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

安装开发环境

不安装则无法使用javac

[root@iZk0g7y0r8vpc5Z bin]# yum install java-1.8.0-openjdk-devel.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.292.b10-1.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================================================
 Package                                                            Arch                                             Version                                                             Repository                                         Size
=================================================================================================================================================================================================================================================
Installing:
 java-1.8.0-openjdk-devel                                           x86_64                                           1:1.8.0.292.b10-1.el7_9                                             updates                                           9.8 M

Transaction Summary
=================================================================================================================================================================================================================================================
Install  1 Package

Total download size: 9.8 M
Installed size: 40 M
Is this ok [y/d/N]: y
Downloading packages:
java-1.8.0-openjdk-devel-1.8.0.292.b10-1.el7_9.x86_64.rpm                                                                                                                                                                 | 9.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:java-1.8.0-openjdk-devel-1.8.0.292.b10-1.el7_9.x86_64                                                                                                                                                                       1/1 
  Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.292.b10-1.el7_9.x86_64                                                                                                                                                                       1/1 

Installed:
  java-1.8.0-openjdk-devel.x86_64 1:1.8.0.292.b10-1.el7_9                                                                                                                                                                                        

Complete!

  • 测试验证
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are used
  -classpath <path>          Specify where to find user class files and annotation processors
  -cp <path>                 Specify where to find user class files and annotation processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release
  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified profile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file

环境变量配置

查询java安装目录

[root@iZk0g7y0r8vpc5Z jvm]# which java
/usr/bin/java
[root@iZk0g7y0r8vpc5Z jvm]# ls -lrt /usr/bin/java
lrwxrwxrwx 1 root root 22 May 15 23:01 /usr/bin/java -> /etc/alternatives/java
[root@iZk0g7y0r8vpc5Z jvm]# ls -lrt /etc/alternatives/java
lrwxrwxrwx 1 root root 73 May 15 23:01 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/bin/java

配置JAVA_HOME

vi /etc/profile

在文件末尾添加,下面配置,JAVA_HOME为上面查询到的路径,也就是Java安装目录

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/bin/java
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

生效配置

[root@iZk0g7y0r8vpc5Z jvm]# source /etc/profile

验证

注意 echo $JAVA_HOME 输出的Java安装目录,与我们配置的目录一致表示配置成功

[root@iZk0g7y0r8vpc5Z jvm]# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
[root@iZk0g7y0r8vpc5Z jvm]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64/jre/bin/java

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值