javac : command not found
Asked Answered
E

12

130

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
Exobiology answered 23/3, 2011 at 15:33 Comment(1)
It looks like your solution is to use yum to install java-1.6.0-openjdk-devel.x86_64Sanfred
C
144

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, e.g.

su -c 'yum provides javac'

on more recent releases of CentOS e.g. 6 the command changes to

su -c 'yum provides */javac'
Cyrie answered 23/3, 2011 at 15:43 Comment(5)
yes, i am sure. just look at the java-1.6.0-openjdk.x86_64 package information (scroll to the "Files" section) and see that there is no javac in that package. and then look at the OpenJDK Development Environment package.Cyrie
Thanks for your help.. I have used "yum install java-1.6.0-openjdk-devel.x86_64"Exobiology
On Fedora 20 yum provides javac outputs "No matches found".Sundae
but he installed 'openjdk', right? JDK means java development kitBaywood
If you had an older javac installed, you may need to sudo alternatives --config javac to make javac point to the newly installed version.Garv
P
197

Worked for me with this command:

yum install java-devel
Putsch answered 1/3, 2012 at 22:8 Comment(5)
But that installs the obsolete JDK 6. Why doesn't it install JDK 8? "yum install java" does install JRE 8.Whoreson
You can grep the output of "yum list" to find the version of java you want, then do "yum install <package>". For me, it was "yum install java-1.7.0-openjdk-devel.x86_64"Calliope
For java8 use sudo yum install java-1.8.0-openjdk-develMerchant
this should be the answer.Bode
Other java installs dint provide javac wasted 2 hrs until i stumbled up on thisEngleman
C
144

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, e.g.

su -c 'yum provides javac'

on more recent releases of CentOS e.g. 6 the command changes to

su -c 'yum provides */javac'
Cyrie answered 23/3, 2011 at 15:43 Comment(5)
yes, i am sure. just look at the java-1.6.0-openjdk.x86_64 package information (scroll to the "Files" section) and see that there is no javac in that package. and then look at the OpenJDK Development Environment package.Cyrie
Thanks for your help.. I have used "yum install java-1.6.0-openjdk-devel.x86_64"Exobiology
On Fedora 20 yum provides javac outputs "No matches found".Sundae
but he installed 'openjdk', right? JDK means java development kitBaywood
If you had an older javac installed, you may need to sudo alternatives --config javac to make javac point to the newly installed version.Garv
O
31

Use the following sudo command:

sudo yum install java-1.6.0-openjdk-devel
Operetta answered 6/3, 2012 at 21:4 Comment(0)
R
2

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.

Respirable answered 23/3, 2011 at 15:45 Comment(0)
S
2

Install same version javac as your JRE

yum install java-devel
Smalltime answered 20/12, 2018 at 6:5 Comment(0)
H
2

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.

Hinojosa answered 9/4, 2020 at 4:11 Comment(0)
P
2

This worked for me: sudo dnf install java-<version>-devel

Polyethylene answered 30/6, 2020 at 15:36 Comment(0)
A
1

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?

Athanasius answered 23/3, 2011 at 15:40 Comment(4)
My problem is where the javac executable will be present by defaultExobiology
doesn't centos have the locate command? as suggested by @RichardAthanasius
I'm sorry, BenCr, I corrected a typo (javajc => javac) but the system only allows to correct at least 6 characters, so I changed something more. On Unix type systems (is CentOS some kind of Unix?) you have to specify ./ to start something in the current directory. Feel free to reedit, if my edits get approved.Suber
did you accept the wrong answer? if so, please change to the right one so as not to confuse readers.Cyrie
H
0

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.

Hermit answered 2/1, 2020 at 13:20 Comment(0)
O
0

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
Oilcan answered 6/6, 2020 at 6:42 Comment(0)
M
0

for java 8 use sudo yum install java-1.8.0-openjdk-devel

Mu answered 10/1, 2022 at 6:43 Comment(0)
O
-2

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.

Outshout answered 14/4, 2015 at 2:9 Comment(1)
The operating system the OP names is CentOS.Stealth

© 2022 - 2024 — McMap. All rights reserved.