简体   繁体   中英

javac command not working in linux environment

I had successfully installed java on my linux system. 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 javac command it gave me following response:

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_HOME env. variable using echo $JAVA_HOME its showing: /usr/lib/jvm/java-8-openjdk-amd64

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

and with command whereis java its showing: 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 javac command running? can any one look into this problem.

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.

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

yum install java-devel

or if you are on the latest Fedora

dnf install java-devel

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

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

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

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM