1.现象:在CentOS7上面,运行javac未发现命令,但是运行java正常。

[root@z6 ~]# javac

bash: javac: command not found...

Similar command is: 'java'

 

[root@z6 ~]# java -version

openjdk version "1.8.0_242"

OpenJDK Runtime Environment (build 1.8.0_242-b08)

OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)


2.进一步发现缺少jdk-devel包,有JDK包jre_1.8.0和jre_1.7.0

 

[root@z6 ~]# yum list |grep java

java-1.7.0-openjdk.x86_64               1:1.7.0.251-2.6.21.1.el7       @anaconda

java-1.7.0-openjdk-headless.x86_64      1:1.7.0.251-2.6.21.1.el7       @anaconda

java-1.8.0-openjdk.x86_64               1:1.8.0.242.b08-1.el7          @anaconda

java-1.8.0-openjdk-headless.x86_64      1:1.8.0.242.b08-1.el7          @anaconda

javapackages-tools.noarch               3.4.1-11.el7                   @anaconda

python-javapackages.noarch              3.4.1-11.el7                   @anaconda

tzdata-java.noarch                      2019c-1.el7                    @anaconda

abrt-java-connector.x86_64              1.0.6-12.el7                   c7-media

java-1.6.0-openjdk.x86_64               1:1.6.0.41-1.13.13.1.el7_3     c7-media

java-1.6.0-openjdk-devel.x86_64         1:1.6.0.41-1.13.13.1.el7_3     c7-media

java-1.7.0-openjdk-devel.x86_64         1:1.7.0.251-2.6.21.1.el7       c7-media

java-1.8.0-openjdk-devel.x86_64         1:1.8.0.242.b08-1.el7          c7-media

java-11-openjdk.x86_64                  1:11.0.6.10-3.el7              c7-media

java-11-openjdk-headless.x86_64         1:11.0.6.10-3.el7              c7-media

java-atk-wrapper.x86_64                 0.30.4-5.el7                   c7-media

javamail.noarch                         1.4.6-8.el7                    c7-media

javassist.noarch                        3.16.1-10.el7                  c7-media

libguestfs-java.x86_64                  1:1.40.2-9.el7                 c7-media

libvirt-java.noarch                     0.4.9-4.el7                    c7-media

libvirt-java-devel.noarch               0.4.9-4.el7                    c7-media

mysql-connector-java.noarch             1:5.1.25-3.el7                 c7-media

nuxwdog-client-java.x86_64              1.0.5-1.el7                    c7-media

pki-base-java.noarch                    10.5.17-6.el7                  c7-media

system-switch-java.noarch               1.1.7.1-0.el7                  c7-media

 

3.一般的解决方法:先卸载当前Java,再安装jdk-linux-x64.tar.gz,修改环境变量。

这种方法费时费力,可能误删文件。


4. 更好的方法:直接安装jdk-devel包,事半功倍。

 

[root@z6 ~]# yum install java-1.8.0-openjdk-devel.x86_64

如果不能连接互联网yum,则参考​https://blog.51cto.com/u_147655/2639367​ 建立yum


5.检验javac

[root@z6 ~]# javac -version

javac 1.8.0_242


 [root@z6 ~]# javac

javac已正常运行,不再报错。