java javac命令在linux环境中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45771615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:53:28  来源:igfitidea点击:

javac command not working in linux environment

javalinuxjvm

提问by JPG

I had successfully installed java on my linuxsystem. When I ran a hello world test sample from desktop it ran successfully, but then after few days when I again tried to run it from terminal using javaccommand it gave me following response:

我已经成功地在我的linux系统上安装了 java 。当我从桌面运行 hello world 测试示例时,它运行成功,但是几天后,当我再次尝试使用javac命令从终端运行它时,它给了我以下响应:

The program 'javac' can be found in the following packages:
 * default-jdk
 * ecj
 * gcj-5-jdk
 * openjdk-8-jdk-headless
 * gcj-4.8-jdk
 * gcj-4.9-jdk
 * openjdk-9-jdk-headless
Try: sudo apt install <selected package>

When I test my JAVA_HOMEenv. variable using echo $JAVA_HOMEits showing: /usr/lib/jvm/java-8-openjdk-amd64

当我测试我的环境时JAVA_HOME。变量使用echo $JAVA_HOME其显示: /usr/lib/jvm/java-8-openjdk-amd64

its also there with PATHvariable. When I ran a which javacommand its showing: /usr/lib/jvm/java-8-openjdk-amd64/bin/java

它也有PATH变量。当我运行一个which java命令时,它显示: /usr/lib/jvm/java-8-openjdk-amd64/bin/java

and with command whereis javaits showing: java: /usr/lib/jvm/java-8-openjdk-amd64/bin/java /usr/share/man/man1/java.1.gz

并使用命令whereis java显示: java: /usr/lib/jvm/java-8-openjdk-amd64/bin/java /usr/share/man/man1/java.1.gz

So, I don't understand the problem, as I, myself applied the env. variables, and its showing everything perfect, then why is not javaccommand running? can any one look into this problem.

所以,我不明白这个问题,因为我自己应用了 env。变量,它显示一切都很完美,那么为什么javac命令没有运行?任何人都可以研究这个问题。

回答by Edwin Buck

The core problem is that you do not have the Java Develoment Toolkit (which is different than the Java runtime) installed on your system. This means that utilities used to create Java programs (such as javac, jar, etc) are not on your system.

核心问题是您的系统上没有安装 Java 开发工具包(与 Java 运行时不同)。这意味着用于创建 Java 程序的实用程序(例如 javac、jar 等)不在您的系统上。

Thorbj?rn Ravn Andersen gave the answer for Debian-family Linux systems, here's the answer for RedHat-family systems

Thorbj?rn Ravn Andersen 给出了 Debian 系列 Linux 系统的答案,这里是 RedHat 系列系统的答案

yum install java-devel

or if you are on the latest Fedora

或者如果您使用的是最新的 Fedora

dnf install java-devel

回答by Thorbj?rn Ravn Andersen

Undo your environment settings and run sudo apt install openjdk-8-jdk. javac should now be in your path.

撤消您的环境设置并运行sudo apt install openjdk-8-jdk. javac 现在应该在您的路径中。

回答by Jonas

/usr/lib/jvm/java-8-openjdk-amd64/bin/java

/usr/lib/jvm/java-8-openjdk-amd64/bin/java

is not an dir, its an excecuteable. try excecute the following to use javac:

不是目录,它是一个可执行文件。尝试执行以下操作以使用 javac:

/usr/lib/jvm/java-8-openjdk-amd64/bin/javac

or

或者

/usr/lib/jvm/java-8-openjdk-amd64/bin/jstack