简体   繁体   中英

javac : command not found

I have installed java in my CentOS release 5.5 machine using the command yum install java . But I am unable to compile a class using javac.

Do I need to install any other package?

I have tried to locate the javac executable but i am unable to locate it.

/usr/bin/java is linked as follows:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

I have seen the following output by yum list installed |grep java :

java-1.6.0-openjdk.x86_64              1:1.6.0.0-1.16.b17.el5          installed
tzdata-java.x86_64                     2011b-1.el5                     installed

使用此命令为我工作:

yum install java-devel

You installed the Java Runtime Environment (JRE) only, which does not provide javac . For javac , you have to install the OpenJDK Development Environment . You can install java-devel or java-11-devel , which both include javac .

By the way: you can find out which package provides javac with a yum search, eg

su -c 'yum provides javac'

on more recent releases of CentOS eg 6 the command changes to

su -c 'yum provides */javac'

使用以下 sudo 命令:

sudo yum install java-1.6.0-openjdk-devel

I don't know exactly what yum install java will actually install. But to check for javac existence do:

> updatedb
> locate javac

preferably as root. If it's not there you've probably only installed the Java runtime (JRE) and not the Java Development Kit (JDK). You're best off getting this from the Oracle site : as the Linux repos may be slightly behind with latest versions and also they seem to only supply the open-jdk as opposed to the Oracle/Sun one, which I would prefer given the choice.

I use Fedora (currently 31)

Even with JDK's installed, I still need to specify JAVAC_HOME in the .bashrc, especially since I have 4 Java versions using sudo alternatives --configure java to switch between them.

To find java location of java selected in alternatives

readlink -f $(which java)

In my case: /usr/java/jdk1.8.0_241-amd64/jre/bin/java

So I set following in .bashrc to:

export JAVA_HOME=/usr/java/jdk1.8.0_241-amd64/jre/bin/java

export JAVAC_HOME=/usr/java/jdk1.8.0_241-amd64/bin/javac

export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/jre/bin

export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/bin/

Now javac –version gives: javac 1.8.0_241

This is useful for those who want to use Oracle's version. Just remember to change your .bashrc again if you make a change with java alternatives.

安装与JRE相同版本的javac

yum install java-devel

Is the javac executable in a directory that is part of your PATH?

I don't know the CentOS equivalent of the Windows path but if you cd to the java sdk directory and run ./javac does anything happen?

You have installed the Java Runtime Environment(JRE) but it doesn't contain javac.

So on the terminal get access to the root user sudo -i and enter the password. Type yum install java-devel , hence it will install packages of javac in fedora.

Linux Mint 19.3

I installed Java Oracle manually, like this:

$ sudo ln -s /usr/lib/jvm/java-1.8.0_211/bin/javac /usr/bin/javac

这对我sudo dnf install java-<version>-develsudo dnf install java-<version>-devel

对于 java 8 使用sudo yum install java-1.8.0-openjdk-devel

Make sure you install JDK/JRE first.

follow these steps:

open terminal go to your root dictionary by typing

cd /

you will see Library folder

Now follow this path Library/Java/JVM/bin

Once you get into bin you can see the javac file

Now you need to get the path of this folder for that just write this command

pwd

get the path for your javac .

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