虚拟机安装openjdk 输入 javac 报错 javac -version bash: javac: 未找到命令... 相似命令是: ‘java‘

发布时间:2024年01月16日

问题

[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# javac -version
bash: javac: 未找到命令...
相似命令是: 'java'
[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# java -version
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (build 1.8.0_392-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)

[root@#localhost ~]# /opt/cm-5.14.0/share/cmf/schema/scm_prepare_database.sh mysql -h hadoop250 -uroot -p'123456' --scm-host hadoop250 scm scm '123456'
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64
Verifying that we can write to /opt/cm-5.14.0/etc/cloudera-scm-server
/opt/cm-5.14.0/share/cmf/schema/scm_prepare_database.sh:行379: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/bin/java: 没有那个文件或目录
--> Error 127, giving up (use --force if you wish to ignore the error)


[root@#localhost ~]# cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/
[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# ls
jre


[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# javac -version
bash: javac: 未找到命令...
相似命令是: 'java'
[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# java -version
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (build 1.8.0_392-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)
[root@#localhost java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64]# 

原因:

openjdk安装完只有默认的运行环境,没有开发环境

解决办法:

1,运行一下代码安装jdk开发环境
yum install java-1.8.0-openjdk-devel.x86_64

2,配置环境变量
参考

#set java environment
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-0.el8_3.x86_64
export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-0.el8_3.x86_64/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin

我的
单独列出配置文件吧,方便看
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# cat /etc/profile.d/myenv.sh

#jdk
#export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64
#java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
#/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

[root@#localhost ~]# cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# ls
jre
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# yum install java-1.8.0-openjdk-devel.x86_64


[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# ls
ASSEMBLY_EXCEPTION  bin  include  jre  lib  LICENSE  tapset  THIRD_PARTY_README



[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# pwd
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# vim /etc/profile.d/myenv.sh 
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# cat /etc/profile.d/myenv.sh 
#jdk
#export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64
#java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
#/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# ls
ASSEMBLY_EXCEPTION  bin  include  jre  lib  LICENSE  tapset  THIRD_PARTY_README
[root@#localhost java-1.8.0-openjdk-1.8.0.392.b08-2.el7_9.x86_64]# 

source etc/profile
然后javac -version能正常运行了

文章来源:https://blog.csdn.net/m0_58115520/article/details/135613733
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。